racket

Creating a partition of a set in Scheme

会有一股神秘感。 提交于 2019-12-02 19:33:07
问题 I'm pretty new to scheme overall and I'm having some issues with figuring out an assignment for school. So please no full answers, just looking for a little insight or a nudge in the right direction so I can figure this out on my own. The problem is as follows: Given a list of numbers, determine whether two subsets can be made from those numbers of equivalent sum and # of items. So for example, if the given set is (1 1) then my program should return #t, otherwise #f. Here is what I have

Reverse list in Racket in O(n)

↘锁芯ラ 提交于 2019-12-02 18:22:50
问题 I need to write a recursive function in Scheme which takes a list of atoms and reverses it in linear time. I am only allowed to use define, lambda, cons, car, cdr, cond, let, and null? . Here is what I have so far: (define reverse (lambda (lat) (cond ((null? lat) lat) (else (cons (reverse (cdr lat)) (cons (car lat) '())))))) So when I call the function: (reverse '(a b c d)) I get the following output: '(() (((() 4) 3) 2) 1) Any help would be very much appreciated. 回答1: The problem is that if

What is the best Scheme or LISP implementation for OS X?

拟墨画扇 提交于 2019-12-02 15:42:23
I am looking for a version of Scheme or even LISP that I can use to recover some lost Lisp development skills. Some web capabilities would be nice but not essential. I've looked at Plt and MIT scheme and, while both look pretty good, the Plt seems to be more feature rich. I've also looked at Lisp implementations but all of the seem quite expensive. I favor free/inexpensive implementations as this is truly likely to just be occasional hobby programming. What recommendations would you have? Kyle Cronin I'd go with Racket. It may not be as fast as SBCL, but it does have excellent libraries and

“application: not a procedure” while computing binomial

天大地大妈咪最大 提交于 2019-12-02 15:03:33
问题 I am defining a function binomial(n k) (aka Pascal's triangle) but am getting an error: application: not a procedure; expected a procedure that can be applied to arguments given: 1 arguments...: 2 I don't understand the error because I thought this defined my function: (define (binomial n k) (cond ((or (= n 0) (= n k)) 1) (else (+ (binomial(n) (- k 1))(binomial(- n 1) (- k 1)))))) 回答1: In Scheme (and Lisps in general), parentheses are placed before a procedure application and after the final

What are the actual differences between Scheme and Common Lisp? (Or any other two dialects of Lisp)

巧了我就是萌 提交于 2019-12-02 14:11:35
Note: I am not asking which to learn, which is better, or anything like that. I picked up the free version of SICP because I felt it would be nice to read (I've heard good stuff about it, and I'm interested in that sort of side of programming). I know Scheme is a dialect of Lisp and I wondered: what is the actual difference is between Scheme and, say, Common Lisp? There seems to be a lot about 'CL has a larger stdlib...Scheme is not good for real-world programming..' but no actual thing saying 'this is because CL is this/has this'. This is a bit of a tricky question, since the differences are

Upside down text

╄→гoц情女王★ 提交于 2019-12-02 12:53:13
问题 How would you design a program that will take in a string of lower case letters and produce the string upside down? so if I type in home i get ǝɯoɥ upside down. I've tried looking for in the book to get started, but nothing. 回答1: Try this, a bit of a brute-force approach but works quite well for uppercase, lowercase and number characters - all other characters are presented just as they come: (define upside-map '#hash( (#\a . #\ɐ) (#\b . #\q) (#\c . #\ɔ) (#\d . #\p) (#\e . #\ǝ) (#\f . #\ɟ) (#

Turning structural recursion into accumulative recursion in Racket

∥☆過路亽.° 提交于 2019-12-02 12:20:22
I have some code to find the maximum height and replace it with the associated name. There are separate lists for height and names, each the same length and non-empty. I can solve this using structural recursion but have to change it into accumulative, and I am unsure how to do that. All the examples I have seen are confusing me. Is anybody able to turn the code into one using accumulative recursion? (define (tallest names heights) (cond [(empty? names) heights] [(> (first heights) (first (rest heights))) (cons (first names) (tallest (rest (rest names)) (rest (rest heights))))] [else (tallest

bitmap in dr racket [closed]

蹲街弑〆低调 提交于 2019-12-02 12:06:09
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . how to load a bitmap on a frame (gui) in dr racket??? please give the necessary code and references.... 回答1: I admit, I'm having a hard time finding the right spot in the docs to point you to. Here's some code that does it, but I have a sneaking suspicion that there's a much

Convert from procedure form to let form

有些话、适合烂在心里 提交于 2019-12-02 11:45:17
问题 have this procedure form code that I have written in scheme and I need to change it into let form. Here is procedure form code: (define PI 3.14159265) (define areac (lambda (d) (* PI (/ d 2) (/ d 2)))) (define volumec (lambda (d h) (*(areac d)(/ h 3)))) (define TotalVolume (lambda() (+(volumec 1 1) (volumec 2 2) (volumec 3 3) (volumec 4 4) (volumec 5 5)))) (define main (lambda() (TotalVolume))) (main) Here is what I have implemented so far for my let form code: (define volumec (lambda(d h)

Using car and cdr

笑着哭i 提交于 2019-12-02 11:07:50
I am new to scheme and having a hard time with using car and cdr. I have an AST string literal in ast. (define ast '(program ((assign (var i int) (call (func getint void int) ())) (assign (var j int) (call (func getint void int) ())) (while (neq (var i int) (var j int)) ((if (gt (var i int) (var j int)) ((assign (var i int) (minus (var i int) (var j int)))) ((assign (var j int) (minus (var j int) (var i int))))))) (call (func putint int void) ((var i int))))) ) I know car returns the head of ast. So (car ast) returns 'program. I am confused how to use car and cdr to get strings from ast such