小编Mir*_*lov的帖子

为什么更高阶的程序?

因此,如果一种语言提供更高阶的程序,那么我可以有返回程序的程序.就像是:

(define (Proc a b c)
  (lambda (x) ( #| method body here in terms of a b c and x |# )))
Run Code Online (Sandbox Code Playgroud)

要创建新程序,我会做类似的事情:

(define ProcA (Proc a1 b1 c1)) ; Would create ProcA that has 1 argument
Run Code Online (Sandbox Code Playgroud)

类似的任务可以用不支持高阶过程的语言来完成,方法是定义Proc4个而不是3个参数并调用这个过程来定义ProcA,如:

(define (Proc a b c x) ( #| method body -- does not return any procedure |# )
(define (ProcA x) (Proc a1 b1 c1 x))
Run Code Online (Sandbox Code Playgroud)

那么为什么有关高阶程序的模糊呢?我错过了什么吗?

scheme closures abstraction programming-languages functional-programming

5
推荐指数
1
解决办法
1344
查看次数

在Emacs Lisp中awk'{print $ 2,",",$ 1}'?

偶尔我使用AWK来提取和/或反转数据文件中的列.

awk '{print $2,",",$1}' filename.txt
Run Code Online (Sandbox Code Playgroud)

我如何使用Emacs Lisp做同样的事情?

(defun awk (filename col1 &optional col2 col3 col4 col5)
  "Given a filename and at least once column, print out the column(s)
values in the order in which the columns are specified."
...
)
;; Test awk
(awk "filename.txt" 1); Only column 1
(awk "filename.txt" 2 1); Column 2 followed by column 1
(awk "filename.txt" 3 2 1); Columns 3,2 then 1
Run Code Online (Sandbox Code Playgroud)

样品filename.txt:

a   b  c
1   2  5
Run Code Online (Sandbox Code Playgroud)

样本输出:

b , …
Run Code Online (Sandbox Code Playgroud)

awk elisp

5
推荐指数
1
解决办法
2321
查看次数

将字符串拆分为单个字符

我在Lisp工作时遇到两个问题,我找不到任何解释这个问题的教程或网站.如何将字符串拆分为单个字符?我怎样才能将这些字符更改为相应的ASCII值?如果有人知道解释这些的任何网站或教程视频,他们将不胜感激.

lisp string ascii

5
推荐指数
1
解决办法
2844
查看次数

Emacs:gethash看不到散列表中的键

我在ielm中评估了以下elisp代码:

(setq foo-hash (make-hash-table))

(puthash "location" "house" foo-hash)

(defun foo-start ()
  (interactive)
  (message (gethash "location" foo-hash)))
Run Code Online (Sandbox Code Playgroud)

但是,当我跑(foo-start)(gethash "location" foo-hash)我得到nil回应.进入foo-hashielm回声:#s(hash-table size 65 test eql rehash-size 1.5 rehash-threshold 0.8 data ("location" "house"))

这是一个错误还是我做错了什么?

Emacs版本:24.0.95.1

emacs elisp hashtable

5
推荐指数
1
解决办法
316
查看次数

可以在Emacs中分离迷你缓冲区和回声区域吗?

我很好奇,是否可以分离回声区域和迷你缓冲区,因此两个不同的位置(线,窗格,帧)用于输出消息和输入命令.

正如在不活动期间隐藏Emacs回声区域所述,完全摆脱回声区域是不可能的,但有些提议是:

我有什么选择?理论上可以将回声区域和迷你缓冲区分开吗?它理论上是否需要重写C源代码并重新编译Emacs?请发表任何想法和想法.

emacs elisp minibuffer

5
推荐指数
1
解决办法
949
查看次数

如何在python中找到两个结构相同的列表?

定义一个带有两个输入的过程same_structure.True如果列表具有相同的结构,则应输出 ,False 否则.在以下情况下,两个值p和q具有相同的结构:

Neither p or q is a list.

Both p and q are lists, they have the same number of elements, and each
element of p has the same structure as the corresponding element of q.
Run Code Online (Sandbox Code Playgroud)

编辑:为了使图片清晰,以下是预期的输出

same_structure([1, 0, 1], [2, 1, 2])
    ---> True
same_structure([1, [0], 1], [2, 5, 3])
    ---> False
same_structure([1, [2, [3, [4, 5]]]], ['a', ['b', ['c', ['d', 'e']]]])
    ---> True
same_structure([1, [2, [3, [4, 5]]]], ['a', ['b', ['c', ['de']]]])
    ---> …
Run Code Online (Sandbox Code Playgroud)

python recursion list

5
推荐指数
3
解决办法
604
查看次数

从Emacs运行多字符串bash脚本

我想运行以下bash脚本,它存储在Elisp字符串中,而不是存储在.sh文件中,然后将shell输出存储在变量中.

#!/bin/bash
IFS=: read -ra _dirs_in_path <<< "$PATH"

for _dir in "${_dirs_in_path[@]}"; do
    for _file in "${_dir}"/*; do
        [[ -x ${_file} && -f ${_file} ]] && printf '%s\n' "${_file##*/}"
    done
done
Run Code Online (Sandbox Code Playgroud)

我无法运行shell-command由多个字符串组成的bash脚本.Emacs和Long Shell命令也没有帮助我,因为compile并且comint-run还需要命令,而不是bash语法.

如何从Elisp运行复杂的bash脚本?

emacs shell executable elisp

5
推荐指数
1
解决办法
735
查看次数

组织模式中的POM(点或标记)

我想使用的功能org-entry-propertiesorg-id-get,它们都使用一个可选的参数pom.例如,org-entry-properties文档说:

获取点或标记POM条目的所有属性.

Emacs手册几乎没有提到"marker"这个词,但是有几个函数以-marker.现在我有几个问题.

  1. 什么是点或标记?
  2. 它与标记环中的标记相同吗?
  3. 如何在组织模式缓冲区中获取标记?
  4. 如何在上面的函数调用中使用此标记?

emacs org-mode

5
推荐指数
1
解决办法
814
查看次数

Haskell:递归地将十六进制字符串转换为整数?

对于我的家庭作业,我需要使用递归函数(根据需要使用尽可能多的辅助方法)将十六进制字符串转换为基数为 10 的整数。

这是我到目前为止所得到的:

-- Question 1, part (c):
hexChar :: Char -> Integer
hexChar ch
    | ch == '0' = 0
    | ch == '1' = 1
    | ch == '2' = 2
    | ch == '3' = 3
    | ch == '4' = 4
    | ch == '5' = 5
    | ch == '6' = 6
    | ch == '7' = 7
    | ch == '8' = 8
    | ch == '9' = 9
    | ch == 'A' …
Run Code Online (Sandbox Code Playgroud)

recursion hex haskell type-conversion

5
推荐指数
2
解决办法
4517
查看次数

直到Haskell中模式的最后一次出现为止

dropWhile请求一个谓词并逐个从列表中删除一个元素,直到谓词第一次为假,然后它只返回剩下的内容.例如,您可以从字符串列表中删除元素,直到找到以斜杠开头的字符串:

> dropWhile (not . isPrefixOf "/") ["a", "b", "/c", "d"]
["/c","d"]
Run Code Online (Sandbox Code Playgroud)

但是如果你想连续删除元素直到你最后一次匹配模式呢?例如,Python的os.path.join接受任意数量的字符串参数.如果任何参数以斜杠开头,则忽略所有参数,其余参数与分隔符连接:

>>> os.path.join("a", "/b", "c", "/d", "e")
'/d/e'
Run Code Online (Sandbox Code Playgroud)

如何连续从列表中删除元素,直到最后一次满足某些条件?

haskell

5
推荐指数
1
解决办法
639
查看次数