标签: parameter-passing

如何将变量传递到 modx 中的子块

我在 ModX 中有一个片段,看起来像这样:

$array = array(
    'id' => 1,
    'title' => 'Title of Story',
    'content' => 'Content of story...'
);

echo $modx->getChunk('chunk_story_page', $array);
Run Code Online (Sandbox Code Playgroud)

我的故事页面 HTML 看起来像这样:

<div class="story">
    <h1>[[+title]]</h1>
    <div class="content">
        [[+content]]
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

现在我希望能够从该块中调用另一个块并通过它传递我的数据。我将以下内容放置在上述 HTML 的下方。

[[$chunk_story_page_extra &title=`[[+title]]`&content=`[[+content]]`]]
Run Code Online (Sandbox Code Playgroud)

不言而喻,但是上面的行没有产生任何输出。

关于我在那条线上可能做错了什么的任何线索吗?我确信这与语法有关。

php parameter-passing modx chunks modx-revolution

0
推荐指数
1
解决办法
3793
查看次数

如何将 volatile 变量传递给 c 中的函数?

我想将以下内容传递给 c 中的函数:

#define GPIO_PORTF_DATA_R (*((volatile unsigned long *)0x400253FC))
Run Code Online (Sandbox Code Playgroud)

以下似乎工作得很好:

void ZeroRegister(unsigned long * _REG) 
{ 
    #define vReg (*((volatile unsigned long *)_REG))
    vReg = 0; 
}
Run Code Online (Sandbox Code Playgroud)

有更好的方法来编码吗?或者我的代码有缺陷?除了它生成的编译器警告之外。

c volatile parameter-passing

0
推荐指数
1
解决办法
2360
查看次数

将路径目录传递给 PowerShell 中的函数

我是 PS 新手,我正在尝试编写一个从全局变量接收参数的函数。我想将从 .txt 文件读取的路径名传递到同一脚本中的函数中。

function GetCorrectChildren ([string] $homepath,$min,$max,$row)
{
    #Testpoint 2
    write-host "homepath = $homepath"
    $ColItem = (Get-ChildItem $homepath |? {$_.PSIsContainer} | sort-object)
}

foreach ($homepath in (Get-Content $PSScriptRoot\homepath_short.txt))
{
    $freeSpace = [win32api]::GetDiskFreeSpace("$homepath").FreeBytesAvailable / 1073741824
    $totalSpace = [win32api]::GetDiskFreeSpace("$homepath").TotalNumberOfBytes / 1073741824 
    $percentageFreeSpace = $freeSpace / $totalSpace * 100

    if($freeSpace -lt $threshold)
    {
    #Testpoint 1
    write-host "homepath = $homepath"
    GetCorrectChildren ("$homepath",$min,$max,$OriRow)
}
Run Code Online (Sandbox Code Playgroud)

对于#Testpoint 1,它正确返回路径名,即\\C:\test1\test_a。然而其中#Testpoint 2却又回归\\C:\test1\test_a 20 30 System.Object
我不明白这是什么20 30 System.Object意思以及它来自哪里?有人可以解释一下吗?谢谢

powershell parameter-passing pathname

0
推荐指数
1
解决办法
2420
查看次数

传递值时与通过引用传递时地图的奇怪突变(Golang)

第一种情况下,我按值传递一个映射: package main

import (
    "fmt"
    "time"
)

func timeMap(z map[string]interface{}) {
    z["updated_at"] = time.Now()
}

func main() {
    foo := map[string]interface{}{
        "Matt": 42,
    }
    timeMap(foo)
    fmt.Println(foo)
}
Run Code Online (Sandbox Code Playgroud)

输出是一个静音地图:

map[updated_at:2009-11-10 23:00:00 +0000 UTC Matt:42]
Run Code Online (Sandbox Code Playgroud)

第二种情况下,代码几乎相同,但通过引用传递:

package main

import (
    "fmt"
    "time"
)

func timeMap(z *map[string]interface{}) {
    (*z)["updated_at"] = time.Now()
}

func main() {
    foo := map[string]interface{}{
        "Matt": 42,
    }
    timeMap(&foo)
    fmt.Println(foo)
}
Run Code Online (Sandbox Code Playgroud)

显然,结果不同:

map[Matt:42 updated_at:2009-11-10 23:00:00 +0000 UTC]
Run Code Online (Sandbox Code Playgroud)

我的期望如下:

  • 当传递值时映射不会静音
  • 当经过参考地图时,像第二种情况一样被静音。然而,在第一种 …

function parameter-passing go mutability

0
推荐指数
1
解决办法
1415
查看次数

for 循环中的 auto 导致“begin”未在此范围内声明

我两天前开始学习 C++,我遇到的这个错误对我来说很模糊,我正在尝试执行以下操作

\n\n
int sumArray(const int arr)\n{\n  int sum = 0;\n  for (auto &n : arr) {\n    sum += n;\n  }\n  return sum;\n};\n\nint main () \n{\n  int numbers[] = {1, 2, 5, 10};\n  return sumArray(numbers);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这与“C++ 之旅”中的示例略有不同,我收到的错误是

\n\n

cpprepl.cpp: In function \xe2\x80\x98int sumArray(int)\xe2\x80\x99:\ncpprepl.cpp:4:18: error: \xe2\x80\x98begin\xe2\x80\x99 was not declared in this scope\n for (auto &n : arr) {\n ^~~\ncpprepl.cpp:4:18: error: \xe2\x80\x98end\xe2\x80\x99 was not declared in this scope\ncpprepl.cpp: In function \xe2\x80\x98int main()\xe2\x80\x99:\ncpprepl.cpp:13:26: error: invalid conversion from \xe2\x80\x98int*\xe2\x80\x99 to \xe2\x80\x98int\xe2\x80\x99 [-fpermissive]\n return …

c++ parameter-passing

0
推荐指数
1
解决办法
5889
查看次数

如何从命令行使用 rscript 命令在 R 中运行作业数组?

R我想知道如何使用该函数运行 500 个并行作业Rscript。我目前有一个R文件的标题位于顶部:

args <- commandArgs(TRUE)
B <- as.numeric(args[1])
Num.Cores <- as.numeric(args[2])
Run Code Online (Sandbox Code Playgroud)

在 R 文件之外,我希望传递要运行的 500 个作业中的哪一个,由B. 另外,我想控制每个作业可用的核心/CPU 数量,Num.Cores

我想知道是否有软件或指南可以实现这一点。我目前有一台 CentOS 7/Linux 服务器,我知道一种方法是安装 Slurm。然而,这很麻烦,我想知道是否有办法用队列执行 500 个作业。谢谢。

hpc r cluster-computing parameter-passing slurm

0
推荐指数
1
解决办法
3025
查看次数

java函数参数的求值顺序是什么

因此,我创建了一个类,允许您有选择地传入其自身的新实例:

public ExampleObject(String name, ExampleObject... exampleObjects) {

}


public static void main(String[] args) {
   ExampleFunction(new ExampleObject("Test", new ExampleObject("Test2")));
}
Run Code Online (Sandbox Code Playgroud)

这将如何执行?是先调用外部 ExampleObject 的构造函数,还是先调用内部构造函数?

java oop constructor function parameter-passing

0
推荐指数
1
解决办法
781
查看次数

如何仅当变量在 Java 中不为 null 时才将其作为参数传递

我有以下代码存根,我正在从属性文件中读取一组值。仅当它们不为 NULL 时,我才需要使用这些值将其作为参数传递给函数。

public static void main(String[] args) {
    String arg1 = "arg1";
    String arg2 = "arg2";
    String arg3 = null;
    String arg4 = "arg4";
    .
    .
    .

    testMethod(arg1, arg2, arg3);
}

public void testMethod(String... values) {

}
Run Code Online (Sandbox Code Playgroud)

在上面的代码片段中。我想用参数 arg1、arg2、arg4 调用 testMethod() 只是因为 arg3 为 NULL。

参数的数量可能会有所不同。它不会一直是 4。

我的代码应该动态检查参数是否为 NULL 并将其传递给 testMethod()。

我可以在 Java 中实现这一点吗?如果是,有人可以帮助我..

java parameter-passing

0
推荐指数
1
解决办法
1211
查看次数

如何在Python中调用作为参数传递的函数

是否可以调用在 Python 中作为参数传递的函数?我试过这样做,但它给出了错误

代码:

def doStuff():
    print("doing stuff")

def doWork():
    print("doing work")

def call_function(func):
    func()

call_function(doStuff())
call_function(doWork())
Run Code Online (Sandbox Code Playgroud)

错误:

TypeError: 'NoneType' object is not callable
Run Code Online (Sandbox Code Playgroud)

python parameter-passing

0
推荐指数
1
解决办法
73
查看次数

如何检测C++中函数的参数列表?

我正在设计一个接口,它接受一个用户定义的函数作为参数,然后在一个内置函数中执行,如下所示。

#include <stdio.h>
#include <vector>
using namespace std;

template <class USERDEF>
void builtin(USERDEF userdef){
    std::vector<int> vec = {1, 2, 3};
    if("parameter list is (vector<int>&)") 
        userdef(vec);
    else if("parameter list is (vector<int>::iterator, vector<int>::iterator)") 
        userdef(vec.begin(), vec.end());
    else 
        exit(-1);
}

void userdef1(vector<int> &vec){
    for(auto it=vec.begin(); it!=vec.end(); it++)
        printf("%d ", *it);
    printf("\n");
}

void userdef2(vector<int>::iterator begin, vector<int>::iterator end){
    for(auto it=begin; it!=end; it++)
        printf("%d ", *it);
    printf("\n");
}

int main(){
    builtin(userdef1);
    builtin(userdef2);
}
Run Code Online (Sandbox Code Playgroud)

在哪里,

  • 函数“builtin”接受用户定义的函数,并通过检测给定函数“userdef”的参数列表来传递参数。
  • 另外两个函数 'userdef1' 和 'userdef2' 用不同的参数列表做同样的事情。

我想知道的是“内置”函数中的“如何实现 if-else 语句”?

c++ parameters arguments parameter-passing

0
推荐指数
1
解决办法
60
查看次数