AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[function](coding)

Martin Hope
UlrichH
Asked: 2025-04-03 15:35:52 +0800 CST

在 COBOL 中使用内部函数后比较字段

  • 7

我尝试使用内在函数 upper-case 和 trim 来比较 COBOL 中的两个字段。

当我比较这两个字段而不将结果移动到新字段时,比较结果显示字段相等但实际上并不相等,例如在我的示例中为“Wert1”<>“wert1 x”。

为什么当我使用字段时比较可以按预期进行,而当我直接使用内部函数时却不行?

示例程序:

       program-id. tintr.
       data division.
       working-storage section.

       01  ws-feld1   pic x(10).
       01  ws-feld2   pic x(10).
       01  ws-feld3   pic x(10).
       01  ws-feld4   pic x(10).

       procedure division.

           move "Wert1 " to ws-feld1
           move "wert1 x" to ws-feld2
      *
           display "<" function upper-case(ws-feld1) ">"
           display "<" function upper-case(ws-feld2) ">"
      *
           display "<" function trim(ws-feld1) ">"
           display "<" function trim(ws-feld2) ">"
      *
           display "<" function upper-case
           (function trim(ws-feld1)) ">"
           display "<" function upper-case
           (function trim (ws-feld2)) ">"
      * Compare WS-Feld1/WS-Feld2
           if ws-feld1 = ws-feld2
           then
              display " felder1-2 identical"
           else
              display " felder1-2 not identical"
           end-if
      * Compare Functions uppercase/Trim
           if function upper-case
           (function trim(ws-feld1))
           =
            function upper-case
           (function trim(ws-feld2))
           then
              display " felder1-2/function identical"
           else
              display " felder1-2/function not identical"
           end-if
      * moving result of functions into field
           move function upper-case
           (function trim(ws-feld1))
           to ws-feld3
           
           move function upper-case
           (function trim(ws-feld2))
           to ws-feld4
      * Compare WS-Feld3/WS-Feld4
           if ws-feld3 = ws-feld4
           then
              display " felder3-4 identical"
           else
              display " felder3-4 not identical"
           end-if
      *

           stop run.

      *

结果如下:

<WERT1     >
<WERT1 X   >
<Wert1>
<wert1 x>
<WERT1>
<WERT1 X>
felder1-2 not identical
felder1-2/function identical
felder3-4 not identical

没想到结果是“felder1-2/functionidentical”:

对于这种行为有什么解释吗?

function
  • 1 个回答
  • 33 Views
Martin Hope
jshrager
Asked: 2025-02-26 01:52:48 +0800 CST

在 SBCL Lisp 中获取函数参数列表

  • 5

在 SBCL 中,当我描述 lambda 时,我得到了很多细节:

* (setf f (lambda (a b) (* a b)))
#<FUNCTION (LAMBDA (A B)) {535B3C3B}>                                                                                                               
* (describe f)
#<FUNCTION (LAMBDA (A B)) {535B3C3B}>
 [compiled function]
Lambda-list: (A B)
Derived type: (FUNCTION (T T) (VALUES NUMBER &OPTIONAL))
Documentation: T                                                                                                                                                 
Source form: (LAMBDA (A B) (* A B))                                                                                                                            

我如何访问这些对象?具体来说,我想访问 lambda 列表。

谢谢!

function
  • 1 个回答
  • 23 Views
Martin Hope
InStackOfHelp
Asked: 2025-02-09 05:08:26 +0800 CST

此 LET 公式输出 2 列数据。我想将其输出到 3 列,并在两列数据之间留出一个空白列

  • 5

我在谷歌表格中。我写了一个公式,将数据输出到两列中。我希望在中间插入一个空白列,因为最终第一列将与第二列合并。我尝试使用输出变量,然后嵌套两个索引函数,每个函数在 {} 之间引用 filterstatus,但没有成功。有什么想法吗?我试图让公式尽可能保持动态。

    =LET(
      filtertype,
        IFERROR(SORT(IFNA(FILTER({Set[CardName], CHOOSE(MATCH(G52,{"All","Base","Master"},0),Set[AllOwn],Set[BaseOwn],Set[MasterOwn])},Set[Player]=F42),"No Match"))),
      filterstatus,
        ArrayFormula(IFNA(IF(G53="All", filtertype, FILTER(filtertype,INDEX(filtertype,0,2)= G53)), "Blank")),
      filterstatus
    )
function
  • 1 个回答
  • 22 Views
Martin Hope
haifisch123
Asked: 2025-01-13 23:30:21 +0800 CST

嵌套函数无法识别输入

  • 9

这是我的问题的一个简单例子:

innerFunc([2, 4, 5]) % works fine
outerFunc(innerFunc, [2, 4, 5]) % doesn't work

function out = innerFunc(my_vec) 
    my_vec % not recogniced when called from outerFunc
    out = -1;
end

function out = outerFunc(func, my_vec) 
    out = func(my_vec);
end

这是代码的输出:


my_vec =

     2     4     5


ans =

    -1

Not enough input arguments.

Error in nested_funcs_bug>innerFunc (line 5)
    my_vec % not recogniced when called from outerFunc

Error in nested_funcs_bug (line 2)
outerFunc(innerFunc, [2, 4, 5]) % doesn't work

>> 

我不知道为什么第二行出现错误?

特别是因为“innerFunc”通常可以工作并且我将 outerFunc 函数中的输入传递给它。

function
  • 1 个回答
  • 39 Views
Martin Hope
Brian Obot
Asked: 2025-01-01 08:27:08 +0800 CST

使用 Instant::now 调用在 Rust 中测量时,两个空函数会产生不同的运行时间

  • -1

我用 rust 编写了两个空函数,希望用它们来测试向量上 retain 的使用或在迭代器上 filter 的使用,在为每种情况编写空函数后,在运行程序时,我注意到每个函数的持续时间之间存在巨大差异,这意味着在当前空函数中添加任何逻辑都会导致对其执行时间得出错误的结论。

use std::time::Instant;

fn use_filter() {
    
}

fn use_retain() {
    
}

fn run_multiple(f: fn(), times: u64) {
    for _ in 0..times {
        f()
    }
} 

fn main() {
    let iter_count: u32 = 1_000_000_000;
    
    let _start_1 = Instant::now();
    run_multiple(use_filter, iter_count as u64);
    let duration = Instant::now() - _start_1;
    println!("Use Filter duration: {:?}", duration / iter_count);
    
    let _start_2 = Instant::now();
    run_multiple(use_retain, iter_count as u64);
    let duration = Instant::now() - _start_2;
    println!("Use Retain duration: {:?}", duration / iter_count);
}

预期输出

Use Filter duration: xns
Use Retain duration: xns

其中 x 对于两个函数来说都是相同的,因为它们都是空的并且不执行任何操作

实际产量

Use Filter duration: 8ns
Use Retain duration: 10ns

什么可以解释 rust 编程语言中空函数的执行时间差异很大。

function
  • 2 个回答
  • 78 Views
Martin Hope
Vlad
Asked: 2024-12-12 13:52:05 +0800 CST

Coq 错误语法错误:[gallina] 后应为 '.'(在 [vernac_aux] 中)

  • 5

所以我有这个代码:

Require Import Unicode.Utf8.
Require Import String.

Inductive AExp :=
| avar : string → AExp 
| anum : nat → AExp 
| aplus : AExp → AExp → AExp 
| amul : AExp → AExp → AExp.

Coercion anum : nat >-> AExp.
Coercion avar : string >-> AExp.
Notation "A +' B" := (aplus A B) (at level 50, left associativity).
Notation "A *' B" := (amul A B) (at level 40, left associativity).

Inductive BExp :=
| btrue : BExp
| bfalse : BExp
| bnot : BExp → BExp
| band : BExp → BExp → BExp
| blessthan : AExp → AExp → BExp
| bgreaterthan : AExp → AExp → BExp.

Notation "A <' B" := (blessthan A B) (at level 80).
Notation "A >' B" := (bgreaterthan A B) (at level 80).
Infix "and'" := band (at level 82).
Notation "! A" := (bnot A) (at level 81).

Inductive Stmt :=
| assignment : string → AExp → Stmt 
| while : BExp → list Stmt → Stmt
| seq : Stmt → Stmt → Stmt
| obj_inst : string → string → Stmt
| method_invoke : string → string → list AExp → Stmt.

Notation "X ::= A" := (assignment X A) (at level 85).
Notation "S1 ;; S2" := (seq S1 S2) (at level 99, right associativity).

Inductive Method :=
| method : string → list Stmt → Method.

Inductive Class :=
| class : string → list (string * AExp) → list Method → Class.

Definition Point :=
  class "Point"
    [("x", anum 0) ("y", anum 0)]
    [
      method "move" [
        assignment "x" (aplus (avar "x") (anum 1));
        assignment "y" (aplus (avar "y") (anum 1))
      ]
    ].

Definition CreatePoint : Stmt :=
  obj_inst "p" "Point".

Definition MovePoint : Stmt :=
  method_invoke "p" "move" [].

Definition SampleProgram :=
  seq CreatePoint MovePoint.

我得到了这个错误:

语法错误:[gallina] 后应为“.”(在 [vernac_aux] 中)。我不确定是否是因为Definition Point.

尝试使用 chatGpt,但没有用。使用它我浪费了很多时间。(我不知道该写些什么,这样 StackOverflow 才会允许我发布这个问题)

function
  • 1 个回答
  • 27 Views
Martin Hope
anf
Asked: 2024-11-21 10:14:42 +0800 CST

我如何更改最长和最短的函数以避免在 Python 中重复代码?

  • 5

我正在用 Python 编写一个程序来查找数组中最短和最长的字符串,例如这是 find_shortest

def find_shortest(words):
 
    N = len(words)
    shortest = words[0]
    i = 1
    while i < N:
        if len(shortest) >= len(words[i]): #Change only this line for find_longest
            shortest = words[i]
        i += 1

    return shortest

我的问题是 find_longest 函数与 find_shortest 函数完全相同,只是 find_longest 使用 <= 符号而不是 >=。我不想复制粘贴 find_shortest 函数来制作 find_longest,但我没有其他选择。在这种情况下,如何避免复制粘贴和冗余?

function
  • 4 个回答
  • 14 Views
Martin Hope
gstackoverflow
Asked: 2024-11-02 16:13:09 +0800 CST

有没有办法在不破坏现有调用的情况下向函数(具有 var args)添加一个具有默认值的参数?

  • 6

我有一个功能

fun foo(
    id: String,
    vararg values: Int,
){
  ...    
}

还有这样的呼吁

fun bar1(){
    foo("id_1")
    foo("id_2", 1)
    foo("id_3", 1, 2, 3)
}

现在我明白了我需要向 foo 添加一个参数。但我不想破坏现有的调用,所以我尝试使用默认值添加它:

fun foo(
    id: String,
    attributes: Array<String> = arrayOf("a", "b"),
    vararg values: Int,
){
  ...
}

但

foo("id_2", 1)
foo("id_3", 1, 2, 3)

变得破碎。

有没有办法在不破坏现有调用的情况下添加一个具有默认值的参数?

function
  • 2 个回答
  • 22 Views
Martin Hope
Alan Demelenne
Asked: 2024-10-16 00:19:54 +0800 CST

如果单元格为空白则删除所有列

  • 6

如果此列的第一个单元格为空白,我会尝试编写一个脚本来删除该列。第 1 行有时有内容,有时为空白。我想要一个宏,当第 1 行的单元格为空白时,该宏将删除整个列并检查下一列,直到第 1 行的单元格不再为空白(例如,如果 A1 为空白,则删除 A 列并转到下一列,直到所有列都已测试)。

我无法弄清楚我在哪里犯了代码错误。

我尝试了一个已有的脚本,用于逐行删除,直到没有带有特定空白单元格的行(我尝试自己修改它,以便也将其用于列)。该脚本可以工作,但什么也没做,我没有任何错误。他在这里:

function delmonth() {
    var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
    spreadsheet.setActiveSheet(spreadsheet.getSheetByName('CALMON'), true);

    var sheet = SpreadsheetApp.getActiveSheet();
    var e = sheet.getRange('A' + sheet.getMaxColumns())
                 .getNextDataCell(SpreadsheetApp.Direction.NEXT)
                 .getColumn() ;

    for (k = 1; k <= e; k++) {
        if(sheet.getRange('A' + k).getValue() == '') {
            sheet.deleteColumn(k);
            k=1;
            e--;
            if(k==e) {
                break
            };
            SpreadsheetApp.flush();
        }
    }
}

我很确定我在某个地方犯了一个愚蠢的错误(因为我对编码还不熟悉)。

感谢大家的时间和帮助!

function
  • 1 个回答
  • 59 Views
Martin Hope
user27519555
Asked: 2024-09-29 01:25:58 +0800 CST

Haskell 中出现未知错误,导致函数无法运行

  • 6

我对 haskell 非常陌生,我接到一个任务,要创建一个属性列表,然后创建一个函数,输出适用于输入的属性列表,但由于某种原因,它只给我一个错误。下面是代码片段和错误

properties :: [Predicate Thing]
properties = [isBlue, isThick, isThin, isOrange, isDisc, isSquare, isBig, isSmall]

propertiesOf :: Thing -> [Predicate Thing] 
propertiesOf x = [props | props <- properties, props x == True]

错误如下:

<interactive>:8:1: error: [GHC-39999] * No instance for Show (Thing -> Bool)'arising from a use of print' (maybe you haven't applied a function to enough arguments?) * In a stmt of an interactive GHCi command: print it

我希望输入一个橙色的、圆盘状的、大而厚的“东西”,并接收输出:

>[isBig, isDisc, isOrange, isThick]

我不确定为什么上面列出的功能不起作用。

function
  • 1 个回答
  • 37 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve