我为Guile开发了一个扩展模块,用C语言编写.这个扩展模块嵌入了一个Python解释器.
由于此扩展模块调用Python解释器,我需要验证它是否正确管理Python对象占用的内存.
我发现Python解释器在其自己的内存处理中表现良好,因此通过运行valgrind,如果没有其他干扰因素,我可以发现由于我自己的Python解释器嵌入代码中的错误导致的内存泄漏.
但是,当我在valgrind下运行Guile时,valgrind会报告内存泄漏.由于我自己的代码,这种内存泄漏会掩盖任何内存泄漏.
问题是如何将由于我的代码中的错误导致的内存泄漏与valgrind报告的内存泄漏(由于Guile导致的内容泄漏)分开.另一个工具而不是valgrind?特殊的valgrind选项?放弃并依赖手动代码演练?
我正在玩诡计,试图熟悉纯函数式编程概念.在我可以用任何语言做任何有用的事情之前,我需要了解一些基本的数据结构以及如何有效地操作它们......特别是可枚举的数据结构.
我可以迭代这样的列表(我不确定我是否正确缩进):
(map (lambda (v)
(display (string-append v "\n"))
'(1 2 3))
=>
1
2
3
Run Code Online (Sandbox Code Playgroud)
散列表/哈希映射在scheme中是什么样的?是否有真正的数据结构来表示一个,或者它是否归结为列表列表?在这种情况下,如何将键和值作为单独的变量从内部列表中获取?
显然这是错误的,因为lambda期望一个值,而不是两个:
(map (lambda (key value)
(display (string-append key " => " value))
'('("one" 1) '("two" 2) '("three" 3)))
Run Code Online (Sandbox Code Playgroud)
我正在尝试做的Ruby相当于:
{ "one" => 1, "two" => 2, "three" => 3 }.map do |key, value|
puts "#{key} => #{value}"
end
Run Code Online (Sandbox Code Playgroud) 我正在重新熟悉计划,并且遇到了一个问题,这可能反映了我的根本误解。
假设我在Scheme中执行以下操作(在本例中使用Guile,但在Chicken中是相同的):
> (define x 5)
> x
5
> (string->symbol "x")
x
> (+ 5 (string->symbol "x"))
<unnamed port>:45:0: In procedure #<procedure 1b84960 at <current input>:45:0 ()>:
<unnamed port>:45:0: In procedure +: Wrong type: x
> (symbol? (string->symbol "x"))
#t
> (+ 5 x) ; here x is dereferenced to its value 5
10
> (+ 5 'x) ; here x is not dereferenced
<unnamed port>:47:0: In procedure #<procedure 1c7ba60 at <current input>:47:0 ()>:
<unnamed port>:47:0: In procedure +: …
Run Code Online (Sandbox Code Playgroud) 我创建了一个abc.scm文件,并尝试在 Ubuntu 的终端中使用“ guild compile ”、“ scm ”和“ guile ”命令将其编译为二进制文件(或任何编译为的 guile 方案)。
对于“ guild compile abc.scm ”,我得到的输出“写为‘/home/tarunmaganti/.cache/guile/ccache/2.0-LE-8-2.0/home/tarunmaganti/abc.scm.go’ ”我找到了文件并像这样运行 - “ ./abc.scm.go ”表示权限被拒绝。
当我使用“ chmod 755 ”或“ chmod 777 ”授予必要的权限时,出现类似 - “ bash: ./abc.scm.go: cannot execute binary file: Exec format error ”的错误。
“ scm what-file-name.scm ”只是打开scm解释器。
" guile 任何文件名.scm什么都不做。
官方 GNU/Guile Scheme 的链接不是很有帮助。
请帮我。我想创建一个 guile 方案脚本文件。编译它并将其作为 C/C++ 程序运行。是否可以?如果无法编译,我想知道,如何至少运行GNU/guile 方案或MIT-Scheme的脚本文件。
{非常感谢逐步介绍,我仍然是使用 Ubuntu 和 Scheme 的初学者。}
提前致谢。
我尝试运行一个之前用 guile 运行的策略方案脚本。我注意到策略失败了,因为它缺少“格式”功能。
格式不是方案的一部分吗?
(format #t "example(~a)=<~a>\n" i (example i))
Run Code Online (Sandbox Code Playgroud)
相反,我将我的策略脚本修改为以下内容。
(display (string-append "example(" (number->string i) ")=<" (number->string (example i)) ">\n"))
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?谢谢。
我正在尝试学习一些 Guile Scheme,并且正在查看gnu 上的教程:脚本示例
\n\n目前我有以下代码:
\n\n#!/usr/bin/env sh\nexec guile -l fact.scm -e \'(@ (my-module) main)\' -s "$0" "$@"\n!#\n\n;; Explanation:\n;; -e (my-module)\n;; If run as a script run the `my-module` module\'s `main`.\n;; (Use `@@` to reference not exported procedures.)\n;; -s\n;; Run the script.\n\n(define-module (my-module)\n #:export (main))\n\n;; Create a module named `fac`.\n;; Export the `main` procedure as part of `fac`.\n\n(define (n-choose-k n k)\n (/ (fact n)\n (* (fact k)\n (fact (- n k)))))\n\n(define (main args)\n (let ((n (string->number …
Run Code Online (Sandbox Code Playgroud) 我试图端口yield
,并yield from
从Python的方案。
这是我完成的一个实现:
(define (coroutine routine)
(let ((current routine)
(status 'new))
(lambda* (#:optional value)
(let ((continuation-and-value
(call/cc (lambda (return)
(let ((returner
(lambda (value)
(call/cc (lambda (next)
(return (cons next value)))))))
(if (equal? status 'new)
(begin
(set! status 'running)
(current returner))
(current (cons value returner)))
(set! status 'dead))))))
(if (pair? continuation-and-value)
(begin (set! current (car continuation-and-value))
(cdr continuation-and-value))
continuation-and-value)))))
Run Code Online (Sandbox Code Playgroud)
这个实现的问题在于它必须被调用的方式看起来不像 Python 的yield
.
(define why (call/cc (lambda (yield)
(format #t "love me or leave me!")
(yield …
Run Code Online (Sandbox Code Playgroud) scheme continuations guile coroutine delimited-continuations
guile ×10
scheme ×8
compilation ×1
coroutine ×1
debugging ×1
dictionary ×1
emacs ×1
evaluation ×1
gambit ×1
geiser ×1
interpreter ×1
memory-leaks ×1
mit-scheme ×1
python ×1
scripting ×1
shell ×1
symbols ×1
valgrind ×1