racket

How to change printing behaviour in DrRacket for R6RS to print results like with #lang racket

江枫思渺然 提交于 2019-12-30 11:09:10
问题 When I'm running a program in the IDE, version 5.3.5--2013-06-18(-/f), for #lang racket , eg. #lang racket (+ 4 5) (/ 10 2) When pressing Run > , the interaction window gets "9\n5\n" printed to the interactions window. The same version as R6RS #!r6rs (import (rnrs base)) (+ 4 5) (/ 10 2) It seems I get no output when pressing Run > when language is R6RS . Is there anywhere I can change this behavior, in Preferences perhaps? 来源: https://stackoverflow.com/questions/19624049/how-to-change

Matrix multiplication in scheme, List of lists

不羁岁月 提交于 2019-12-29 09:05:15
问题 I started to study Scheme and I do not understand some of it. I'm using DrRacket. I wrote the following code: (define mult_mat (λ (A B) (Trans_Mat (map (λ (x) (mul_Mat_vec A x)) (Trans_Mat B))))) That uses this functions: (define Trans_Mat (λ (A) (apply map (cons list A)))) (define mul_Mat_vec (λ (A v) (map (λ (x) (apply + (map * x v))) A))) In mult_mat , I multiply the matrix A in each vector of the transpose matrix B. It works fine. I found a code on the web that makes the multiplication in

Matrix multiplication in scheme, List of lists

折月煮酒 提交于 2019-12-29 09:05:10
问题 I started to study Scheme and I do not understand some of it. I'm using DrRacket. I wrote the following code: (define mult_mat (λ (A B) (Trans_Mat (map (λ (x) (mul_Mat_vec A x)) (Trans_Mat B))))) That uses this functions: (define Trans_Mat (λ (A) (apply map (cons list A)))) (define mul_Mat_vec (λ (A v) (map (λ (x) (apply + (map * x v))) A))) In mult_mat , I multiply the matrix A in each vector of the transpose matrix B. It works fine. I found a code on the web that makes the multiplication in

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

旧城冷巷雨未停 提交于 2019-12-29 07:12:07
问题 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)) . 回答1: Like others have said, all you need to do is create separate functions to

Differences between #lang scheme and #lang racket

廉价感情. 提交于 2019-12-29 04:11:05
问题 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

Insert Node into a Tree - Racket

与世无争的帅哥 提交于 2019-12-25 16:46:49
问题 I am trying to add a new node to the tree. The following are my definitions and function type: (define-struct (Some T) ([value : T])) (define-type (Option T) (U 'None (Some T))) (define-type BST (U 'E Nd)) (define-struct Nd ([root : Integer] [lsub : BST] [rsub : BST])) (: insert : Integer BST -> BST) ;; insert an item into a tree ;; note: do not insert duplicate items (define (insert n x) (match x ('E 'E) ((Nd ro ls rs) (cond ((= (size x) 1) (Nd ro (Nd n 'E 'E) 'E)) (else (Nd ro ls rs))))))

Racket: argument is non-null error

会有一股神秘感。 提交于 2019-12-25 14:32:33
问题 At first I defined HALF , QUARTER and EIGHT to their values with define and with it the quoted symbols would get introduced as arguments in the note function thus making an error. Then I used let and now I get the error stream-rec->C: argument is not non-null `stream-rec' pointer argument: #f My theory is that stream still processes HALF as 'HALF instead of 30000 . I tried putting it into an eval list in note , in random-length in let bindings and in random-note and neither worked. What can I

Racket: argument is non-null error

匆匆过客 提交于 2019-12-25 14:32:07
问题 At first I defined HALF , QUARTER and EIGHT to their values with define and with it the quoted symbols would get introduced as arguments in the note function thus making an error. Then I used let and now I get the error stream-rec->C: argument is not non-null `stream-rec' pointer argument: #f My theory is that stream still processes HALF as 'HALF instead of 30000 . I tried putting it into an eval list in note , in random-length in let bindings and in random-note and neither worked. What can I

Return the second element for every element in a list

佐手、 提交于 2019-12-25 11:57:31
问题 Let's say we have this list '( (4 (1 2)) (5 (5 5)) (7 (3 1)) (1 (2 3))) I am trying to write smth in Scheme in order to get the second element for every element in the list.. So the result will look like '( (1 2) (5 5) (3 1) (2 3)) I have this code so far.. (define (second list1) (if (null? (cdr list1)) (cdr (car list1)) ((cdr (car list1))(second (cdr list1))))) 回答1: Here's a straightforward solution: (define (seconds lst) (map cadr lst)) In general, when you want to transform every element

Binary Search Tree To List Scheme

此生再无相见时 提交于 2019-12-25 08:13:49
问题 I am having trouble understanding how to take in a BST and convert it into a list without using append or any advanced techniques. For example, you are given a BST with each node having a number and a name (sorted by string smallest to largest) and you want to output a list, in order, of the items in that BST with a value of 3 or something along these lines. I understand this can be done recursively but I think my biggest problem with understanding this has to do with the splitting of the