racket

Scheme Find all possible paths for an undirected graph

╄→гoц情女王★ 提交于 2019-12-13 02:19:51
问题 I am having problem to print out all the possible paths. Currently I am only able to print out one path, and if (path-demo "J" "I"), the program will shown this error mcdr: expects argument of type <mutable-pair> ; given #f (define net '(("A" "B") ("B" "A" "C") ("C" "B" "D") ("D" "C" "E" "F") ("F" "I" "D") ("I" "F") ("E" "D" "J") ("J" "E" "G") ("G" "J" "H"))) (define (path-demo start finish) (for-each (lambda (x) (display x) (display " ")) (cons "Route:" (shortest-path start finish net))))

Getting a specific hash-table from a list in racket?

好久不见. 提交于 2019-12-13 00:26:03
问题 So I'm trying to parse JSON from the Riot API, and I'm having a little trouble trying to get a specific hash-table. From what I understand, the api call is giving me a hash table, and in this table there is one other hash table, and in that table, is a large, variable amount of hash tables, each with another hash table. The table that I get {"summonerId":35979437,"modifyDate":1428864068000,"champions": [{"id":40,"stats": {"totalSessionsPlayed":2,"totalSessionsLost":1,"totalSessionsWon":1,

What's a recursive way to move the second element of a list to the front? [Racket]

ぐ巨炮叔叔 提交于 2019-12-12 22:34:02
问题 How can I recursively move the middle of a 3-element list to the front of the list? There are nested lists. So, ((not #f) iff (((#f implies #t) and #t) or #f)) Should become (iff (not #f) (or (and (implies #f #t) #t) #f)) 回答1: It's a really good use of match because we can set a condition for the 3-element list and simply ignore the other cases - (define (transform l) (match l ((list a b c) (list (transform b) (transform a) (transform c))) (_ l))) (transform '((not #f) iff (((#f implies #t)

how to create a macro in racket where a list becomes the args of said lambda?

徘徊边缘 提交于 2019-12-12 22:22:47
问题 How would I go about in doing a define-syntax-rule that accepts a list as arguments and a list (or a quote, in case it is a single element) as body of a lambda? i would like to do something like: >(define a (lambdarize '(x y z) '(+ x y z))) #<procedure> >(a 1 2 3) 6 >(define b (lambdarize '(x) 'x)) #<procedure> >(b 1) 1 I have played around with define-syntax-rule and apply , but since lambda itself seems to be a macro and not a procedure, i have been stumped at trying to find it... oh... And

Calling a fortran routine as a Scheme function

大憨熊 提交于 2019-12-12 21:17:13
问题 Is it possible to call a Fortran routine as a Scheme function? I could find nothing by searching the web. 回答1: The answer depends on which implementation you use. Here is an example of writing bindings in Racket. The bindings are for CBLAS and LAPACK. The CBLAS library is C based and LAPACK is Fortran based. Therefore you can see both styles. (Unfinished) Racket bindings for CBLAS and LAPACK 回答2: Is it possible? Technically, yes. Most modern Fortran compilers (e.g. ifort, gfortran) support

How do you detect key presses on a Racket web application?

荒凉一梦 提交于 2019-12-12 21:02:28
问题 I've been through the documentation for web-servers and can't find anything on it. Here's my code for a basic web application: #lang racket (require web-server/servlet web-server/servlet-env) (define test '()) (define (start request) (define bindings (request-bindings request)) (cond ((exists-binding? `cb1 bindings) (set! test '(1 2 3)) (printf "~a" "(test) has been set to '(1 2 3)!"))) (response/xexpr `(html (head (title "My Blog")) (body (h1 "Under construction") (form ,`(input ((name "cb1"

List passed to procedure converts into list of list inside the procedure

余生长醉 提交于 2019-12-12 18:32:50
问题 I'm debugging this code on DrRacket: #lang racket (define last-element-on-list (lambda l (cond ((null? l) '()) ((null? (cdr l)) (car l)) (else (last-element-on-list (cdr l))) ) ) ) (define lst '( (n 25 f +) (s 25 m +) (ll 20 no -))) (list-ref lst 0) (last-element-on-list (list-ref lst 0)) The code (list-ref lst 0) returns '(n 25 f +) , but when I get into the procedure last-element-on-list the parameter l has the value ((n 25 f +)) . Why l is a list of list in procedure last-element-on-list ?

unfold function in scheme

守給你的承諾、 提交于 2019-12-12 16:17:36
问题 Goal: implement unfold function using only two arguments. The arguments: the first argument is f which takes an initial value of some type I and returns nil or a cons pair of two elements (the first of these two is the next element that goes in the list of some type A and the next initial value again of some type I). The second argument is an initial value of some type I and the return is a list of items of type A. This is what I have so far and I am not sure why it is not working: (define

Scheme: why is Internal Definition faster than External Definition?

会有一股神秘感。 提交于 2019-12-12 15:46:31
问题 I tried running the program below (define (odd-internal x) (define (even x) (if (zero? x) #t (odd-internal (sub1 x)))) (if (zero? x) #f (even (sub1 x)))) (define (odd-external x) (if (zero? x) #f (even (sub1 x)))) (define (even x) (if (zero? x) #t (odd-external (sub1 x)))) (begin (display "Using internal definition\n") (time (odd-internal 40000000))) (begin (display "Using external definition\n") (time (odd-external 40000000))) This is the result in Racket Using internal definition cpu time:

Create suffixed numbers Racket

被刻印的时光 ゝ 提交于 2019-12-12 14:55:26
问题 I'm trying to experiment with what I can do in Racket, and I want to suffix numbers with letters. For this example, I'd simply like to represent 10000 as 10K , and 1000000 as 1M . Is there way (with macros or otherwise) that I can expand 1M to: (* 1 1000000) Or something to that effect? 回答1: In Racket, things like 10K are identifiers , which normally would refer to variables. There are two ways to make them into numbers: 1: redefine what "undefined" identifiers mean You can redefine what to