racket

How to write a scheme function that takes two lists and returns four lists

谁说我不能喝 提交于 2019-11-29 08:13:34
I have 2 lists of elements '(a b c) '(d b f) and want to find differences, union, and intersection in one result. Is that possible? How? I wrote a member function that checks if there is a car of the first list in the second list, but I can't throw a member to the new list. (define (checkResult lis1 lis2) (cond........... )) (checkresult '( a b c) '(d b f)) My result should be (( a c) (d f) (a b c d f) (b)) . Like others have said, all you need to do is create separate functions to compute the intersection, union, and subtraction of the two sets, and call them from checkresult: (define

How do I pass a list as a list of arguments in racket?

僤鯓⒐⒋嵵緔 提交于 2019-11-29 06:06:38
I have a statement like this: ((lambda (a b c) (+ a b c)) 1 2 3) ; Gives 6 And I would like to be able to also pass it a list as so: ((lambda (a b c) (+ a b c)) (list 1 2 3)) ...except this doesn't work because the entire list is passed as 'a.' Is there is a way to explode the list into arguments? What I'm looking for is something similar to the * character in Python. For those of you unfamiliar with the syntax: def sumthree(a, b, c): print a + b + c sumthree(1, 2, 3) # Prints 6 sumthree(*(1, 2, 3)) # Also prints 6 That operation is called apply . (apply + (list 1 2 3)) ; => 6 apply "expands"

Racket: execute file and stay in interactive mode

霸气de小男生 提交于 2019-11-29 03:28:20
问题 Is there a way from a command line to run Racket file and stay in the interactive mode afterwards? E.g. same in Python it would be: python -i <file.py> 回答1: Assuming a foo.rkt that's this: #lang racket (provide x) (define x 42) (define y 4242) Then you can use -i to specify interactive mode (= REPL), together with -t to require the file: $ racket -it foo.rkt Welcome to Racket vX.X.X. > x 42 > y y: undefined; ... > (exit) Note that y is not bound since it's in the module and not provided out.

How do I define functions using Racket macros?

孤街浪徒 提交于 2019-11-28 23:56:24
I am trying to write a macro that defines a special class of data structure with associated functions. I know this is possible; it is done multiple times in the core language itself. As a specific example, how would I define the define-struct macro in Scheme itself. It needs to create make-struct , struct-<<field>> , etc functions. I tried doing this using define , however, this only defines the function in the macro's lexical scope. How can I actually define a function in a macro? The key for an answer is datum->syntax . The basic idea is that you want to take some random data and turn it

Check if an argument is a list or an atom

家住魔仙堡 提交于 2019-11-28 21:29:45
How do I check if something is an atom? I'm looking for something like number? or list? . Usually, you'll want to exclude the empty list too: (define (atom? x) (not (or (pair? x) (null? x)))) or, if you want to be more pedantic, then forbid vectors too: (define (atom? x) (not (or (pair? x) (null? x) (vector? x)))) And of course you can add much more here -- since it's marked as a racket question, you might want to add hash tables, structs, etc etc. So it can just as well be easier to specify the kinds of values that you do consider as atoms: (define (atom? x) (ormap (lambda (p) (p x)) (list

Differences between #lang scheme and #lang racket

与世无争的帅哥 提交于 2019-11-28 21:16:42
I'm guessing that #lang racket is a dialect of scheme with much more out of the box structures and common functions and perhaps would be more pedagogic. What are the perks a #lang racket against #lang scheme? Is it best (or even possible) to use #lang scheme in racket to follow all the content of 'Structure and Interpretation of Computer Programs' or even 'How to Design Programs'. HtDP is #lang racket specific? Whatever code written in #lang scheme, as long as libraries are not being included, can be used in chicken scheme or any main interpreter? Thanks in advance. Eli Barzilay Yes, #lang

Programming Scheme(Racket) with VIM - How to get started

痴心易碎 提交于 2019-11-28 21:05:15
问题 recently, I started programming Racket (formerly Scheme) in DrRacket. I quite fast I began to miss all the features of VIM in DrRacket, so I would like to use VIM for my scheme(racket) programming. I know that Emacs might be the best choice for intense lisp programming, but all I want is write a scheme(racket) file check syntax and then run it. Unfortunately, I could not figure out, how to invoke "racket" in the commandline on a file to get it doing the same as DrRacket. I am running Ubuntu

Little Schemer and Racket

巧了我就是萌 提交于 2019-11-28 18:47:48
I'm starting to read the Little Schemer and now instead of PLT Scheme we have Racket. I would like to know if Racket is suitable for doing the exercises in the book or do I need to get another true Scheme compiler. Before I forgot to tell you, my OS is Windows x64. The book, language and paradigm is complex enough, I would love to avoid struggling with a compiler. Thanks a lot in advance. DrRacket is the (r)evolution of DrScheme; DrRacket will work perfectly for the exercises in "The Little Schemer". Just don't forget to: In the Language dialog, choose "Use the language declared in the source"

Dr Racket problems with SICP

耗尽温柔 提交于 2019-11-28 16:51:48
I'm working through SICP. Currently, in the first chapter, I'm having problems getting Racket to let me redefine "primitives". For instance, I was under the impression that I should be able to arbitrarily do (define + 5) and that would be fine, or redefine the sqrt procedure. Instead, I get this: define-values: cannot change constant variable: + I have the language currently set to R5RS, which I was under the impression would take care of the compatibility issues with SICP. Eli Barzilay Even if possible, such redefinitions are not something that you should do without really understanding how

What exactly is a “continuation prompt?”

别说谁变了你拦得住时间么 提交于 2019-11-28 16:02:16
问题 I'm trying to decipher the documentation call-with-continuation-prompt Applies proc to the given arg s with the current continuation extended by a prompt. The prompt is tagged by prompt-tag , which must be a result from either default-continuation-prompt-tag (the default) or make-continuation-prompt-tag . The result of proc is the result of the call-with-continuation-prompt call. I understand the part where it says "Applies proc to the given arg s with the current continuation" and then it's