在Scheme中迭代(Iterating in Scheme)
假设我在Scheme中有一个列表列表,如下所示:
(define a-list (list (list a b) (list c d) (list e f) (list g h) (list i j)))
我将如何定义一个消耗此列表的函数,以便我可以使用另一个函数来使用列表中的每个字母?
例如,我有另一个功能
(define (smorg a) (...))
那么,我怎么去做smorg a,smorg b,smorg c ......?
Let's say that I have a list of lists in Scheme, like so:
(define a-list (list (list a b) (list c d) (list e f) (list g h) (list i j)))
How would I go about defining a function that would consume this list such that I could use another function to consume each letter in the list?
For instance, I had another function
(define (smorg a) (...))
So, how do I go about doing smorg a, smorg b, smorg c... ?
原文:https://stackoverflow.com/questions/7426987
最满意答案
您可以通过引用它们的完整路径
Kernel.==
来管道输入这些运算符(在Kernel
中定义)Kernel.==
:iex(1)> 0 |> Kernel.==(0) true iex(2)> 1 |> Kernel.==(0) false
You can pipe into such operators (which are defined in
Kernel
) by referring to their full path,Kernel.==
:iex(1)> 0 |> Kernel.==(0) true iex(2)> 1 |> Kernel.==(0) false
相关问答
更多-
什么是“pin”运算符,并且Elixir变量是否可变?(What is the “pin” operator for, and are Elixir variables mutable?)[2021-08-16]
Elixir中的数据仍然是不变的,但有几个简写,让你输入较少或不必担心找到新名字。 在Erlang中,你经常可以看到如下代码: SortedList = sort(List), FilteredList = filter(SortedList), List3 = do_something_with(FilteredList), List4 = another_thing_with(List3) 在Elixir中,你可以写出: list = sort(list) list = filter(list) li ... -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
在elixir中什么是=〜操作符(What is =~ operator in elixir)[2022-02-05]
它没有记录在该页面上,但它在Kernel.=~/2记录Kernel.=~/2 ,当RHS是字符串时, =~检查LHS是否包含RHS: iex(1)> "foo" =~ "f" true iex(2)> "foo" =~ "o" true 它不会将RHS隐式转换为正则表达式: iex(3)> "foo" =~ "." false It's not documented on that page, but it's documented in Kernel.=~/2 that when the RHS is ... -
在上面的示例中,您已将匿名函数fn x -> x + x end绑定到变量double 。 传递命名函数时使用捕获运算符。 保存/传递一个命名函数,你需要一种方法来表明它是一个命名函数,而不是一个变量。 这是您使用capture&name / arity语法的地方。 defmodule FunWithFuns do def get_env, do: Application.get_all_env(:my_app) def get_env(item), do: Application.get_env( ...
-
Elixir中的等式运算符是否有前缀/波兰表示法?(Is there a prefix/Polish notation for the equality operator in Elixir?)[2024-04-30]
您可以通过引用它们的完整路径Kernel.==来管道输入这些运算符(在Kernel中定义) Kernel.== : iex(1)> 0 |> Kernel.==(0) true iex(2)> 1 |> Kernel.==(0) false You can pipe into such operators (which are defined in Kernel) by referring to their full path, Kernel.==: iex(1)> 0 |> Kernel.==(0) t ... -
是和不是。 do / end是关键字列表的句法便利。 你以前可能写过表情。 人们可能期望看到的是类似的东西 if predicate do true_branch else false_branch end 这也可以使用关键字列表来编写。 以下内容完全相同。 if predicate, do: true_branch, else: false_branch 使用do / end符号允许我们在编写代码块时删除冗长的内容。 以下两个if表达式是等价的 if predicate do a = fo ...
-
1 = x是可能欺骗了你的人为例子。 通常,匹配运算符确保RHO与LHO匹配,这意味着LHO没有违反RHO的内容。 这不是完全匹配,因为LHO可能通常a)确保只有RHO的一部分匹配,b)可能比等式检查( == )更宽松。 在1的情况下, 1井是1 ,这就是为什么这个例子看起来很人为。 另一方面, =匹配运算符是通用语法,涵盖所有情况。 1 === 1在javascript中也看起来有点奇怪,有人可能会问“为什么我需要三等号”,只看这个例子。 另一方面,匹配运算符用于: 函数子句匹配 def print(1) ...
-
Map.put_new(event, :key, "value") Map.put_new(event, :key, "value")
-
你的解析树应该是这样的: '-' | +---+---+ | | '+' '4' | +---+---+ | | '1' '3' 每个节点都有两个指针。 一个是左边的孩子,一个是右边的孩子。 使用递归遍历时,不需要指向父节点的指针。 这是一些伪代码: 遍历中缀表示法 : void traverse(Node *node) { if (node->leftChild != 0) { ...
-
这个. (点)运算符是一种特殊形式 。 来自文档 : 特殊形式是Elixir的基本构建块,因此不能被开发人员覆盖。 The . (dot) operator is a special form. From the docs: Special forms are the basic building blocks of Elixir, and therefore cannot be overridden by the developer.