racket

Do Racket streams memoize their elements?

拜拜、爱过 提交于 2020-01-01 12:31:13
问题 Does Racket use memoization when computing large amounts of numbers from an infinite stream? So, for example, if I printed out (aka, computed and displayed) the first 400 numbers on the infinite stream of integers: (1 2 3 ... 399 400) And right after I asked to print the first 500 numbers on this infinite stream. Would this second set of computations use memoization? So the first 400 numbers would not be computed again? Or does this functionality need to be coded by the user/obtained from

Anonymous lambdas directly referring to themselves

≯℡__Kan透↙ 提交于 2020-01-01 10:37:21
问题 Does Scheme or do any dialects of scheme have a kind of "self" operator so that anonymous lambdas can recur on themselves without doing something like a Y-combinator or being named in a letrec etc. Something like: (lambda (n) (cond ((= n 0) 1) (else (* n (self (- n 1))))))) 回答1: No. The trouble with the "current lambda" approach is that Scheme has many hidden lambdas. For example: All the let forms (including let* , letrec , and named let ) do (which expands to a named let ) delay , lazy ,

Anonymous lambdas directly referring to themselves

倾然丶 夕夏残阳落幕 提交于 2020-01-01 10:36:50
问题 Does Scheme or do any dialects of scheme have a kind of "self" operator so that anonymous lambdas can recur on themselves without doing something like a Y-combinator or being named in a letrec etc. Something like: (lambda (n) (cond ((= n 0) 1) (else (* n (self (- n 1))))))) 回答1: No. The trouble with the "current lambda" approach is that Scheme has many hidden lambdas. For example: All the let forms (including let* , letrec , and named let ) do (which expands to a named let ) delay , lazy ,

(define (average …)) in Lisp

妖精的绣舞 提交于 2020-01-01 09:36:13
问题 I'm just playing around with scheme/lisp and was thinking about how I would right my own definition of average . I'm not sure how to do some things that I think are required though. define a procedure that takes an arbitrary number of arguments count those arguments pass the argument list to (+) to sum them together Does someone have an example of defining average ? I don't seem to know enough about LISP to form a web search that gets back the results I'm looking for. 回答1: The definition

How do you load a file into racket via command line?

最后都变了- 提交于 2020-01-01 01:15:37
问题 I have been trying to launch a racket program from the commandline (via 'racket') but have not been having success. According to the documentation (here http://docs.racket-lang.org/reference/running-sa.html#%28part._mz-cmdline%29) passing -f followed by a file should evaluate that file. However, I can't seem to get this to work. As a test, I made the following file: ;test.rkt #lang racket (define a 1) Then, running it in racket (supposedly loading the file) and attempting to recall the value

Converting numbers to english letter list

假装没事ソ 提交于 2019-12-31 05:42:10
问题 I have the function below which converts an input of numbers into the partially translated word output of those numbers. Using product and quotient, it adds the word representation of numbers while splitting the number into groups. For example: (number-name 87969087) -> '(87 million 969 thousand 87) (number-name 1000000) -> '(1 million) Im trying to complete my problem by fully translating those numbers which are less than 1000 as well. Im trying to implement a function less-than-1000 which

Trying to get this code to work, can't understand where to put the argument in and keep getting errors

*爱你&永不变心* 提交于 2019-12-31 05:08:28
问题 Define the function iota1(n, m) that takes positive integers n, m with n < m as input, and outputs the list (n,n+1,n+2,...,m) I've tried switching the code around multiple times but cannot seem to get it to function and display a list the right way (define (iota1 n m) (if (eq? n 0) '() (append (iota1 (< n m) (+ n 1)) (list n)))) 回答1: There's a few oddities to the code you provided, which I've formatted for readability: (define (iota1 n m) (if (eq? n 0) '() (append (iota (< n m) (+ n 1)) (list

A function which will determine that if a passed in list follows an A B pattern

和自甴很熟 提交于 2019-12-31 04:13:09
问题 (define fun4 (lambda ( ls) (cond ((null? ls ) #f) (cons (((eqv? 'a (car ls))) && ((eqv? 'b (cdr ls))))) (else (pattern2 cdr ls))))) In this it showing error - procedure application: expected procedure, given: #t (no arguments), What is the erroe in my code. Is logic is fine ??? 回答1: There are many, many errors in your solution. Let's see what's wrong in each of the conditions: The base case of the recursion (empty list) is wrong: an empty list is the exit of the recursion, and it means that

How to take intersection of pairs from two lists in scheme?

↘锁芯ラ 提交于 2019-12-31 04:08:08
问题 I am using this script from The little schemer, to get intersection of two sets. But I am getting unbound identifier error at 'member?', can anyone please tell what's wrong with it: (define intersect (lambda (set1 set2) (cond ((null? set1) (quote ())) ((member? (car set1) set2) (cons (car setl) (intersect (cdr set1) set2))) (else (intersect (cdr setl) set2))))) I was missing this function above: (define member? (lambda (a lat) (cond ((null? lat) #f) (else (or (eq? (car lat) a) (member? a (cdr

BSL (How to Design Programs): how to import code from a separate file into definitions area?

若如初见. 提交于 2019-12-31 02:58:11
问题 I'm having an issue with BSL. I want to divide my code into separate auxiliary files and use (require "auxiliary-function.rkt") at the beginning to import the separated code into the definitions area. However it doesn't work as supposed. Though no explicit error given, it seems like that that DrRacket simply doesn't see the code in the separate file and all I see is the error <auxiliary-function-name>: this function is not defined Apparently, (provide x) is not included in BSL. I've read the