scheme

Scheme # void error

吃可爱长大的小学妹 提交于 2019-12-11 05:16:38
问题 I tried running the following scheme code: (define affiche-gagnant (lambda (j1 j2 g1 g2) (begin (display "Le gagnant est : ") (display (cond ((> g1 g2) j1) ((< g1 g2) j2) (else (begin (display "personne. ") (display j1) (display " et ") (display j2) (display " sont exaequos. ")))))))) But I get the following output: Le gagnant est : personne. Alper et Ezgi sont exaequos. #<void> Where did the #void come from? How do I get rid of it? 回答1: Oops, wrong answer. You have an extra display: (define

A function builder in scheme

让人想犯罪 __ 提交于 2019-12-11 05:15:56
问题 A function I'm supposed to build is supposed to take in a list of numbers as a parameter, and give a single function as an output that does as follows: If the number in the list is a positive number, add it, if it is negative multiply by it, and if it is 0, square the number. For example, if I pass in (4 -1 0), it should return a function that takes in a single parameter, adds 4 to it, multiplies it by -1, squares it, and returns that. I think I'm on the right track, but I'm getting seriously

Scheme storing the result of a function (Let)

怎甘沉沦 提交于 2019-12-11 05:05:11
问题 (define [DML vara] (cond ((atom? (car vara)) (cond ((eqan? (car vara) 'N) (display (cdr vara))) (else (negate vara))) ))) I'm currently trying to save the content of a return right now for simplicity I was testing the negate function it "returns" a list and I wanted to save the result of that function to do testing. How do I actually save the list return from negate. Kind of like (x = (negate vara)) where x is the list. I look up let on google and in stack over flow but I can't find a very

The Order of Variable and Function Definitions

倾然丶 夕夏残阳落幕 提交于 2019-12-11 05:04:37
问题 Why is it that: Function definitions can use definitions defined after it while variable definitions can't. For example, a) the following code snippet is wrong: ; Must define function `f` before variable `a`. #lang racket (define a (f)) (define (f) 10) b) While the following snippet is right: ; Function `g` could be defined after function `f`. #lang racket (define (f) (g)) ; `g` is not defined yet (define (g) 10) c) Right too : ; Variable `a` could be defined after function `f` #lang racket

Hide extra separator lines between empty menu items

感情迁移 提交于 2019-12-11 04:43:44
问题 Separator lines still appear after hiding menu-items from this link => Can't hide "Preferences" item in edit-menu I have searched in racket documentation and found only adding new separator menu item. https://docs.racket-lang.org/gui/separator-menu-item_.html Is it possible to hide these extra lines between empty menu items? 回答1: Separator lines are created in the "between" methods. Those are removed by using void . #lang racket/gui (require framework) (define menu-super-frame% (frame

define-syntax issue in scheme

孤人 提交于 2019-12-11 04:29:48
问题 I'm wondering what is going wrong with how I'm defining my for-loop in scheme. Whenever I try running a for statement with it it runs for quite a while and then crashes. (define-syntax for (syntax-rules (:) [(_ (initial : test : update) body) (begin initial (if test (begin body update (for [test : update] body))))] [(_ (test : update) body) (if test (begin body update (for [test : update] body)))])) It should run the initial condition, check the test, run the body, and then loop to the next

How to replace an element in a specific position of a list?

空扰寡人 提交于 2019-12-11 04:15:25
问题 I want to replace an element in a specific position of a list. I have this so far: (define alon (list 1 2 3 4 5 6 7 8 9 10)) (define pos (list 3 6 9)) ;; list with positions to be replaced (define insert (list "a" "b" "c")) ;;replacement (define (list-insert xalon xpos xins counter) (cond ((empty? xins) (cons (rest xalon) '())) ((= counter (first pos)) (cons (first xins) (list-insert (rest xalon) (rest xpos) (rest xins) (add1 counter)))) (else (cons (first xalon) (list-insert (rest xalon)

Implementing has-list in scheme

对着背影说爱祢 提交于 2019-12-11 04:14:27
问题 how can you implement a Scheme function has-list recursively, which tests whether a list contains other list as an element. For example (has-list '(1 2 3)) should return false, and (has-list '(1 2 (3 4) 5)) should return true. 回答1: If your implementation has something like ormap , then: (define (has-list? l) (ormap list? l)) Using or as in Dan D.'s answer will not work. 回答2: A list has a list as an element iff it is not the empty list and either its first element is a list or the rest of the

Macro for keyword and default values of function arguments in Racket

泄露秘密 提交于 2019-12-11 04:12:12
问题 Keyword and default arguments can be used in Racket functions as shown on this page: https://docs.racket-lang.org/guide/lambda.html (define greet (lambda (#:hi [hi "Hello"] given #:last [surname "Smith"]) (string-append hi ", " given " " surname))) > (greet "John") "Hello, John Smith" > (greet "Karl" #:last "Marx") "Hello, Karl Marx" > (greet "John" #:hi "Howdy") "Howdy, John Smith" > (greet "Karl" #:last "Marx" #:hi "Guten Tag") "Guten Tag, Karl Marx" Since Racket is said to be able to

Cons in scheme explanation

此生再无相见时 提交于 2019-12-11 03:56:56
问题 (cons 1 2) gives us (1 . 2) . (cons 3 4) gives us (3 . 4) . So why does (cons (cons 1 2) (cons 3 4)) give us ((1 . 2) 3 . 4) ? Why isn't it ((1 . 2) (3 . 4)) ? 回答1: Well, it wouldn't be ((1 . 2) (3 . 4)) because that would be a list containing two elements, each a cons pair. I'm guessing what you meant was: why isn't it ((1 . 2) . (3 . 4)) ? Well, actually the following two expressions are equivalent: '((1 . 2) . (3 . 4)) '((1 . 2) 3 . 4) This has to do with how Scheme's dotted notation works