racket

How to show different content based on the path in Racket web servlets?

天涯浪子 提交于 2019-12-06 06:04:22
问题 I'm trying to follow the tutorial on the Racket guide on simple web apps, but can't get one, basic, basic thing. How can you have a servlet serve different content based on the request URL? Despite my scouring, even the huge blog example was one big file and everything handled with huge get query strings behind my back. How can I do anything based on URLs? Clojure's Noir framework puts this basic feature big up front on the home page ( defpage ) but how to do this with Racket? 回答1: The URL is

Applying A List of Functions to a Number

▼魔方 西西 提交于 2019-12-06 03:57:02
问题 I understand that functions in Scheme/Racket like map, foldr, and filter, can do wonderful things like apply a function to a list of elements. Is it possible to apply a list of functions to a single element? I would like to generate the values produced by each of the functions, then find their maximum. Thank you. 回答1: For the first part, this procedure will apply a list of functions to a single argument, assuming that all the functions receive only one argument. A list with the results is

DrRacket EOPL Scheme output

给你一囗甜甜゛ 提交于 2019-12-06 03:51:49
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 interaction pane and see the output, but this is tedious when I have multiple expressions I want to evaluate

List to string conversion in Racket

浪尽此生 提交于 2019-12-06 03:31:02
问题 How do I convert a list into a string in DrRacket? For example, how do I convert '(red yellow blue green) into "red yellow blue green"? I tried using list->string but that seems to work only for characters. 回答1: The trick here is mapping over the list of symbols received as input, converting each one in turn to a string, taking care of adding a white space in-between each one except the last. Something like this: (define (slist->string slst) (cond ((empty? slst) "") ((empty? (rest slst))

Scheme code cond error in Wescheme

青春壹個敷衍的年華 提交于 2019-12-06 00:01:07
Although the following code works perfectly well in DrRacket environment, it generates the following error in WeScheme: Inside a cond branch, I expect to see a question and an answer, but I see more than two things here. at: line 15, column 4, in <definitions> How do I fix this? The actual code is available at http://www.wescheme.org/view?publicId=gutsy-buddy-woken-smoke-wrest (define (insert l n e) (if (= 0 n) (cons e l) (cons (car l) (insert (cdr l) (- n 1) e)))) (define (seq start end) (if (= start end) (list end) (cons start (seq (+ start 1) end)))) (define (permute l) (cond [(null? l) '((

How do I include files in DrScheme?

旧城冷巷雨未停 提交于 2019-12-05 21:18:37
I'm using DrScheme to work through SICP, and I've noticed that certain procedures (for example, square ) get used over and over. I'd like to put these in a separate file so that I can include them in other programs without having to rewrite them every time, but I can't seem to figure out how to do this. I've tried: (load filename) (load (filename)) (load ~/path-to-directory/filename) (require filename) (require ~/path-to-directory/filename) (require path-from-root/filename) None of these works. Obviously I'm grasping at straws -- any help is much appreciated. It's not clear from your question

Macro to use dot.notation to get structure fields in Racket

感情迁移 提交于 2019-12-05 20:07:00
For a structure and its instance defined as follows: (struct dog (name breed age)) (define mydog (dog "lassie" "collie" 5)) (example from https://learnxinyminutes.com/docs/racket/ ) The usual way to get a structure field is as follows: (dog-name mydog) ; => "lassie" Can there be a macro so that we can perform above using following dot notation: (mydog.name) ; => "lassie" Or, parentheses may not be needed: mydog.name ; => "lassie" Macro for dot notation is used on this page: http://www.greghendershott.com/fear-of-macros/pattern-matching.html#%28part._hash..refs%29 but I am not able to use it

How do I get an item from a list at a given index in racket language?

给你一囗甜甜゛ 提交于 2019-12-05 17:08:18
问题 I'm trying to get an item from a list at a given index for a loop statement. (define decision-tree-learning (lambda (examples attribs default) (cond [(empty? examples) default] [(same-classification? examples) (caar examples)] ; returns the classification [else (lambda () (let ((best (choose-attribute attributes examples)) (tree (make-tree best)) (m (majority-value examples)) (i 0) (countdown (length best)) ; starts at lengths and will decrease by 1 (let loop() (let example-sub ; here,

What are the benefits of letrec?

孤人 提交于 2019-12-05 13:31:21
问题 While reading "The Seasoned Schemer" I've begun to learn about letrec . I understand what it does (can be duplicated with a Y-Combinator) but the book is using it in lieu of recurring on the already define d function operating on arguments that remain static. An example of an old function using the define d function recurring on itself (nothing special): (define (substitute new old l) (cond ((null? l) '()) ((eq? (car l) old) (cons new (substitute new old (cdr l)))) (else (cons (car l)

Drawing onto canvas% element

三世轮回 提交于 2019-12-05 13:01:10
I have a problem while trying to draw onto a canvas GUI element. I create a frame, a canvas and try to draw on the dc context of the canvas with the draw-line method, but nothing happens. The frame with the canvas is shown, but the line isn't shown on the canvas. (require racket/gui/base) (define frame (new frame% [label "Frame"] [width 500] [height 500])) (define canvas (new canvas% [parent frame])) (define dc (send canvas get-dc)) (send dc draw-line 10 10 200 200) (send frame show #t) Does anybody know where I am wrong in the code above ? Try this: (require racket/gui/base) (define frame