racket

miniKanren: How to define #s and #u?

雨燕双飞 提交于 2021-02-10 00:19:22
问题 In miniKanren, succeed can be defined as (define succeed (== #t #t)) , and fail can be defined as (define fail (=== #t #f)) . But what about #s and #u as short forms of succeed and fail , as they appear in The Reasoned Schemer ? (define #s succeed) produces an error in Racket: Welcome to Racket v7.2. > (require Racket-miniKanren/miniKanren/mk) > (define #s succeed) ; readline-input:2:8: read-syntax: expected `(`, `[`, or `{` after `#s` [,bt ; for context] #<procedure:...iniKanren/mk.rkt:337:4

How are these nested vectors connected?

ぃ、小莉子 提交于 2021-02-09 17:49:04
问题 I've written a piece of code, which creates a vector 'scoreboard' that contains 3 seperate vectors of size 3, all containing the symbol ? at all indices 0-2. When i now execute a 'vector-set!' on the first vector of scoreboard, to change its first element to a 'X, vectors 2 and 3 will change too. How does this occur? (define scoreboard (make-vector 3 (make-vector 3 '?))) (define (display-scoreboard) (display (vector-ref scoreboard 0)) (newline) (display (vector-ref scoreboard 1)) (newline)

How are these nested vectors connected?

自作多情 提交于 2021-02-09 17:47:17
问题 I've written a piece of code, which creates a vector 'scoreboard' that contains 3 seperate vectors of size 3, all containing the symbol ? at all indices 0-2. When i now execute a 'vector-set!' on the first vector of scoreboard, to change its first element to a 'X, vectors 2 and 3 will change too. How does this occur? (define scoreboard (make-vector 3 (make-vector 3 '?))) (define (display-scoreboard) (display (vector-ref scoreboard 0)) (newline) (display (vector-ref scoreboard 1)) (newline)

How are these nested vectors connected?

你离开我真会死。 提交于 2021-02-09 17:47:09
问题 I've written a piece of code, which creates a vector 'scoreboard' that contains 3 seperate vectors of size 3, all containing the symbol ? at all indices 0-2. When i now execute a 'vector-set!' on the first vector of scoreboard, to change its first element to a 'X, vectors 2 and 3 will change too. How does this occur? (define scoreboard (make-vector 3 (make-vector 3 '?))) (define (display-scoreboard) (display (vector-ref scoreboard 0)) (newline) (display (vector-ref scoreboard 1)) (newline)

How are these nested vectors connected?

对着背影说爱祢 提交于 2021-02-09 17:47:09
问题 I've written a piece of code, which creates a vector 'scoreboard' that contains 3 seperate vectors of size 3, all containing the symbol ? at all indices 0-2. When i now execute a 'vector-set!' on the first vector of scoreboard, to change its first element to a 'X, vectors 2 and 3 will change too. How does this occur? (define scoreboard (make-vector 3 (make-vector 3 '?))) (define (display-scoreboard) (display (vector-ref scoreboard 0)) (newline) (display (vector-ref scoreboard 1)) (newline)

What is the difference between an “interned” and an “uninterned” symbol

懵懂的女人 提交于 2021-02-07 14:22:25
问题 What is the difference between an "interned" and an "uninterned" symbol. Is it only Racket that has uninterned symbols or do other dialects of scheme or lisp have them? 回答1: Interned symbols are eq? if and only if they have the same name. Uninterned symbols are not eq? to any other symbol, so they are a kind of unique token with an attached string. Interned symbols are the kind that are produced by the default reader. Uninterned symbols can be used as identifiers when generating code in a

What is the difference between an “interned” and an “uninterned” symbol

北城余情 提交于 2021-02-07 14:21:49
问题 What is the difference between an "interned" and an "uninterned" symbol. Is it only Racket that has uninterned symbols or do other dialects of scheme or lisp have them? 回答1: Interned symbols are eq? if and only if they have the same name. Uninterned symbols are not eq? to any other symbol, so they are a kind of unique token with an attached string. Interned symbols are the kind that are produced by the default reader. Uninterned symbols can be used as identifiers when generating code in a

How to implement a try-catch block in scheme?

和自甴很熟 提交于 2021-02-07 12:15:16
问题 I'm trying to implement a try-catch block in scheme using (call-cc) method but i'm not sure how it can be used for that. I could not find any example. And found examples contains just error-handling but what i want to do is: if an error occurred, the scheme program has to give a message to user (via display for-example) without suspending the program. Is that possible? 回答1: Since you want to catch all errors, such as ones raised by both raise and raise-continuable you'd need both an exception

How to implement a try-catch block in scheme?

岁酱吖の 提交于 2021-02-07 12:14:26
问题 I'm trying to implement a try-catch block in scheme using (call-cc) method but i'm not sure how it can be used for that. I could not find any example. And found examples contains just error-handling but what i want to do is: if an error occurred, the scheme program has to give a message to user (via display for-example) without suspending the program. Is that possible? 回答1: Since you want to catch all errors, such as ones raised by both raise and raise-continuable you'd need both an exception

How the map function implemeted in racket

那年仲夏 提交于 2021-02-05 08:25:13
问题 How does the map function implemented in racket and why, recursion or iteration. Maybe some implementation example 回答1: How to implement map The map function walks a list (or multiple lists), and applies a given function to every value of a list. For example mappiing add1 to a list results in: > (map add1 '(1 2 3 4)) '(2 3 4 5) As such, you can implement map as a recursive function: (define (map func lst) (if (empty? lst) '() (cons (func (first lst)) (map func (rest lst))))) Of course, map