scheme

(Chez) Scheme macro for hiding lambdas

社会主义新天地 提交于 2020-05-13 14:34:12
问题 I would like to write a macro to create shorthand syntax for hiding more verbose lambda expressions, but I'm struggling to understand how to write macros (which I realize is an argument against using them). Given this example: (define alist-example '((x 1 2 3) (y 4 5 6) (z 7 8 9))) (define ($ alist name) (cdr (assoc name alist))) ((lambda (a) (map (lambda (x y z) (+ x y z)) ($ a 'x) ($ a 'y) ($ a 'z))) alist-example) ((lambda (a) (map (lambda (y) (/ y (apply max ($ a 'y)))) ($ a 'y))) alist

Clearing the screen by printing a character?

我的未来我决定 提交于 2020-05-09 21:41:46
问题 I'm using chez-scheme and I can't find a way to clear the screen completely. (If someone knows a better way than printing I'd be interested in that too but it's not my question here) From what I can find clearing the screen by ^L (control-L) or giving the clear command (in bash at least) is equivalent to outputting ASCII character 12: Form feed . However, printing this does nothing. If I use (display (integer->char 12)) it just prints a newline . Another way to encode this character is \f

What are all the cases of ellipsis in Scheme pattern matching Hygienic Macros System

柔情痞子 提交于 2020-04-30 09:21:22
问题 This is continuation of my previous question Missing argument in syntax-rules Hygienic macro call from Scheme R5RS example so you can have only this two cases: First (foo bar baz) ... that can be used as foo ... ==> (foo_1 _ foo_2 _ foo_3 _) bar ... ==> (_ bar_1 _ bar_2 _ bar_3 _) or (foo bar bar) ... but what should expand this expression into? (foo baz) ... Second (foo bar baz ...) which can be used as baz ... that expands into ,@(1 2 3) if input is (anything 0 1 2 3) . Are there any other

What is define* in guile or scheme?

自古美人都是妖i 提交于 2020-04-30 05:12:36
问题 I can't find it by searching, what is define* in guile? You can find it for instance in this answer https://stackoverflow.com/a/24101699/387194 回答1: You will find it in the documentation here: Creating advanced argument handling procedures. 6.10.4.1 lambda* and define*. lambda* is like lambda, except with some extensions to allow optional and keyword arguments. library syntax: lambda* ([var…] [#:optional vardef…] [#:key vardef… [#:allow-other-keys]] [#:rest var | . var]) body1 body2 …

What is define* in guile or scheme?

半世苍凉 提交于 2020-04-30 05:12:21
问题 I can't find it by searching, what is define* in guile? You can find it for instance in this answer https://stackoverflow.com/a/24101699/387194 回答1: You will find it in the documentation here: Creating advanced argument handling procedures. 6.10.4.1 lambda* and define*. lambda* is like lambda, except with some extensions to allow optional and keyword arguments. library syntax: lambda* ([var…] [#:optional vardef…] [#:key vardef… [#:allow-other-keys]] [#:rest var | . var]) body1 body2 …

Difference between define, let and set!

邮差的信 提交于 2020-04-29 05:44:52
问题 Ok, this is a fairly basic question: I am following the SICP videos, and I am a bit confused about the differences between define , let and set! . 1) According to Sussman in the video, define is allowed to attach a value to avariable only once (except when in the REPL), in particular two defines in line are not allowed. Yet Guile happily runs this code (define a 1) (define a 2) (write a) and outputs 2, as expected. Things are a little bit more complicated because if I try to do this (EDIT:

Encode Huffman Tree Scheme

╄→гoц情女王★ 提交于 2020-04-21 05:27:19
问题 I am trying to build a function that encodes the following procedure at the bottom into 1's and 0's can anyone help find why I am getting the error message mpair given: 0. (define (symbols tree) (if (leaf? tree) (list (symbol-leaf tree)) (caddr tree))) (define (right-branch tree) (cadr tree)) (define (left-branch tree) (car tree)) (define (leaf? object) (eq? (car object) 'leaf)) (define (member? x set) (not (equal? (member x set) false))) (define (encode-branch symbol tree) (let ((left (left

Scheme Beginning Student, Function Body Extra Part

我怕爱的太早我们不能终老 提交于 2020-04-17 21:37:36
问题 I attempted to follow the solution provided in this question, but it simply didn't work. Essentially, my function works like so: (define (item-price size normal-addons premium-addons discount) (define price 0) (+ price (* normal-addon-cost normal-addons) (* premium-addon-cost premium-addons) size) (cond .. some conditions here [else price])) However, I am met with the following error: define: expected only one expression for the function body, but found 2 extra parts Now, I've tried wrapping

Scheme Beginning Student, Function Body Extra Part

送分小仙女□ 提交于 2020-04-17 21:37:31
问题 I attempted to follow the solution provided in this question, but it simply didn't work. Essentially, my function works like so: (define (item-price size normal-addons premium-addons discount) (define price 0) (+ price (* normal-addon-cost normal-addons) (* premium-addon-cost premium-addons) size) (cond .. some conditions here [else price])) However, I am met with the following error: define: expected only one expression for the function body, but found 2 extra parts Now, I've tried wrapping

Encoding Huffman Tree Scheme [closed]

萝らか妹 提交于 2020-04-16 02:16:09
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 days ago . I am trying to write a function, (codeWords t) , which traverses a Huffman tree (adds #\0 when it goes left, adds #\1 when it goes right...) and returns these values in pairs of the symbol at a leaf along with its associated encoding as a string over the characters #\0 and #\1 . Similar to what this or