racket

DrRacket EOPL Scheme output

社会主义新天地 提交于 2019-12-10 10:26:44
问题 I am working through the EOPL Scheme exercises using DrRacket in Windows 7. When I switch from #lang racket to #lang eopl, the output from the definitions pane no longer shows up in the interaction pane. To be clear, as trivial example, running #lang racket 4 produces 4 > as you would expect. But running #lang eopl 4 produces only > Is there anything I can do to change this behavior or is there another pane I should be looking at for output? I can, of course, evaluate expressions in the

Sending HTTP POST in Racket

被刻印的时光 ゝ 提交于 2019-12-09 18:31:58
问题 I am trying to send a string via http/post in Racket, this is what I tried so far after reading the Racket HTTP Client Documentation #lang racket (require net/http-client) (define myUrl "https://something.com") (http-conn-send! (http-conn-open myUrl #:ssl? #t) #:version "1.1" #:method "POST" #:data "Hello") But with this I receive the following error: tcp-connect: connection failed detail: host not found address: https://www.w3.org/ port number: 443 step: 1 system error: nodename nor servname

How do I write higher-order functions that take polymorphic functions as arguments in Typed Racket?

走远了吗. 提交于 2019-12-09 15:57:04
问题 For example, how can I write a version of map that will work with polymorphic functions in Typed Racket? I use a simple id function defined as: (: id : (All (A) A -> A)) (define (id x) x) When I try to map it over a list i get an error: > (map id '(1 2 3)) Type Checker: Polymorphic function `map' could not be applied to arguments: Types: (-> a b ... b c) (Listof a) (Listof b) ... b -> (Listof c) (-> a c) (Pairof a (Listof a)) -> (Pairof c (Listof c)) Arguments: (All (A) (-> A A)) (List One

Is there an equivalent to Lisp's “runtime” primitive in Scheme?

大憨熊 提交于 2019-12-09 05:04:30
问题 According to SICP section 1.2.6, exercise 1.22: Most Lisp implementations include a primitive called runtime that returns an integer that specifies the amount of time the system has been running (measured, for example, in microseconds). I'm using DrScheme, where runtime doesn't seem to be available, so I'm looking for a good substitute. I found in the PLT-Scheme Reference that there is a current-milliseconds primitive. Does anyone know if there's a timer in Scheme with better resolution? 回答1:

How to use append-map in Racket (Scheme)

廉价感情. 提交于 2019-12-08 19:51:27
问题 I don't fully understand what the append-map command does in racket, nor do I understand how to use it and I'm having a pretty hard time finding some decently understandable documentation online for it. Could someone possibly demonstrate what exactly the command does and how it works? 回答1: The append-map procedure is useful for creating a single list out of a list of sublists after applying a procedure to each sublist. In other words, this code: (append-map proc lst) ... Is semantically

Selecting student language in Racket source code

杀马特。学长 韩版系。学妹 提交于 2019-12-08 19:34:41
问题 I am trying to write a source file for DrRacket that specifies one of the languages from How to Design Programs Teaching Languages (see the Racket documentation). I know I can select such a language in the DrRacket menu, but I would like to specify it using a #lang directive and have DrRacket recognize the language automatically. I cannot find any documentation about the strings that I need to use instead of racket in the initial line #lang racket Where can I find the documentation on this?

How do collector functions work in Scheme?

末鹿安然 提交于 2019-12-08 17:48:07
问题 I am having trouble understanding the use of collector functions in Scheme. I am using the book "The Little Schemer" (by Daniel P. Friedman and Matthias Felleisen). A comprehensive example with some explanation would help me massively. An example of a function using a collector function is the following snippet: (define identity (lambda (l col) (cond ((null? l) (col '())) (else (identity (cdr l) (lambda (newl) (col (cons (car l) newl)))))))) ... with an example call being (identity '(a b c)

Why isn't a function calling itself in its body considered recursive (vs iterative)?

浪尽此生 提交于 2019-12-08 06:35:15
问题 I am learning Scheme/Racket and am confused with recursion-vs-iteration concept. The specific question is: Write a function that sums up a list of numbers. Take the following code, for example: (define (func list) (define (dostuff list res) (if (empty? list) res (dostuff (cdr list) (+ (car list) res)))) (dostuff list 0)) According to the instructor, this is a iterative solution. But I don't understand why. dostuff is calling itself within its implementation, so doesn't that automatically make

Building the built-in procedure “build-list” in Racket

旧巷老猫 提交于 2019-12-08 06:02:02
问题 I am trying to build the built-in procedure build-list in Racket. The built-in function works like this: (build-list 10 (lambda (x) (* x x))) >> '(0 1 4 9 16 25 36 49 64 81) My implementation is a recursive definition for a recursive procedure: (define (my-build-list-recur list-len proc) (if (= list-len 0) '() (cons (proc (sub1 list-len)) (my-build-list-recur (sub1 list-len) proc)))) When I call my implementation, I have: (my-build-list-recur 10 (lambda (x) (* x x))) >> '(81 64 49 36 25 16 9

How to fix my simplification function for power rule (to make results easier to read) for a working Symbolic differentiation function in Racket?

与世无争的帅哥 提交于 2019-12-08 06:01:36
问题 This is my function for differentiation that works correctly. #lang racket (define (diff x expr) (if (not (list? expr)) (if (equal? x expr) 1 0) (let ( (operation (car expr)) (u (cadr expr)) (v (caddr expr))) (case operation ((+) (list '+ (diff x u) (diff x v))) ((-) (list '- (diff x u) (diff x v))) ((*) (list '+ (list '* u (diff x v)) (list '* v (diff x u)))) ((/) (list '/ (list '- (list '* v (diff x u)) (list '* u (diff x v))) (list '* v v))) ((^) (list '* v (list '* (list '^ u (- v 1))