scheme

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

convert a list of data structure in string, scheme

喜欢而已 提交于 2019-12-25 07:39:20
问题 for example I have this structure: (define-struct example (n1 n2)) and I have this list: (list (make-example 1 3) (make-example 7 9) empty) As I can convert it into string? 回答1: Since you have tagged both racket and scheme (two incompatible languages) I've ignored Scheme completely in my answer. I assume you would not tag racket if you were programming in #!r5rs or #!r6rs. #!racket (define (any->string any) (with-output-to-string (lambda () (write any)))) (any->string '(Hello world)) ; ==> "

Scheme error “except: misuse of unit import keyword”

拜拜、爱过 提交于 2019-12-25 06:51:09
问题 I'm writing a function that returns elements which appear in one list and not in another. For example, (except '(a b c) '(a d b e f)) will return '(c) . The first argument can be an atom, and both are assumed to be flat. Here's my code: (define (except lm ln) (cond ((null? ln) lm) ((not (list? lm)) (cond ((in? lm ln) '()) (#t lm))) ((null? lm) '()) ((in? (car lm) ln) (except (cdr lm) ln)) (#t (cons (car lm) (except (cdr lm) ln))))) Then an error returns saying "except: misuse of unit import

how to write alike display (printf) to file in scheme?

别说谁变了你拦得住时间么 提交于 2019-12-25 06:07:07
问题 Using TinyScheme. I'm writing my code to file (solved it in 50% here: How to write to a file in tinyscheme?) with: (with-output-to-file "biophilia.c" (lambda () (write code) )) ; and segmentation fault comes here but it writes my code with "" qotes and \n\r as is so it doesn't translate it to newline. I need to write code like it looks with (display code) in example in racket docs there is printf but seems like TinyScheme implementation got no printf, maybe I need to discover (add code of it)

Scheme “Not a function” error

寵の児 提交于 2019-12-25 05:36:15
问题 I am learning Scheme and I keep getting this error: "Error: 20 is not a function" from the following code: (define myFunction (lambda (x y) (* x y))) (define (higherOrder func x y) ( func x y)) (display ((higherOrder myFunction 4 5))) I am trying to pass a function as one of the arguments. It goes through with the math since it says "20" in the error message and (5 * 4 = 20) but then it thinks it is a function. What is the problem? I cannot figure it out. I am running this code on https:/

How can I apply each element in a list to a function in scheme?

隐身守侯 提交于 2019-12-25 05:14:15
问题 The function applyToAll is suppose to take in a function and a List, then take the car of the list and apply each element to the fuction. This is what I have worked out so far: (define applyToAll(lambda (f L) (cond ((null? L) '()) (#t (cons (L) (applyToAll f(car L)))) ))) I'm not sure what I am doing wrong. A fuction call would look like (applyToAll (lambda (n) (* n n)) '(1 2 3) ) and it would return (1 4 9) Instead it returns: function call: expected a function after the open parenthesis,

How can I apply each element in a list to a function in scheme?

旧街凉风 提交于 2019-12-25 05:14:13
问题 The function applyToAll is suppose to take in a function and a List, then take the car of the list and apply each element to the fuction. This is what I have worked out so far: (define applyToAll(lambda (f L) (cond ((null? L) '()) (#t (cons (L) (applyToAll f(car L)))) ))) I'm not sure what I am doing wrong. A fuction call would look like (applyToAll (lambda (n) (* n n)) '(1 2 3) ) and it would return (1 4 9) Instead it returns: function call: expected a function after the open parenthesis,

Combining count and flatten functions in scheme

房东的猫 提交于 2019-12-25 04:09:22
问题 So i have these two functions that work fine alone. I am trying to write one function to accomplish both but i keep getting a car error. Any guidance on the best way to solve this? (define (countNumbers lst) (cond ((null? lst) 0) ((number? (car lst))(+ 1 (countNumbers (cdr lst)))) (else (countNumbers (cdr lst))))) (define (flatten x) (cond ((null? x) '()) ((pair? x) (append (flatten (car x)) (flatten (cdr x)))) (else (list x)))) I tried something like this im rather new to functional

Explaining different behavior of variables referenced in continuations?

冷暖自知 提交于 2019-12-25 03:06:22
问题 Following are two case which have different behaviors regarding the value of i across calls to stored continuations. How can the difference be explained? Case A >(define cc #f) >(define (x) (let ((i 0)) (set! i (+ i 100)) (+ i (+ i (call/cc (lambda (k) (set! cc k) 1)))) ; call/cc is not included by set! (set! i (+ i 10)) i)) > (x) 110 > (cc 50) ; the context variable i changes as cc calling 120 > (cc 50) 130 Case B > (define cc #f) > (define (x) (let ((i 0)) (set! i (+ i 100)) (set! i (+ i

Racket string to literal?

六月ゝ 毕业季﹏ 提交于 2019-12-25 02:48:13
问题 I'm doing a project where I'm parsing JSON from the Riot Games API, and I'm having trouble. I'm pretty new to this, so bear with me: The API returns JSON, for example: {"forcinit":{"id":35979437,"name":"F O R C I N it","profileIconId":576,"summonerLevel":30,"revisionDate":1427753158000}} in my code, I have the following: #lang racket (require racket/gui/base net/url json racket/format ) ; --- Query API (define api-request "https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/SUMMONER_NAME