scheme

Mapping multiple functions, in order, over a single list [closed]

与世无争的帅哥 提交于 2020-01-11 12:00:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I would like to map three different functions, in order, over a single list. To demonstrate what I mean, say we want to do the following three mappings: (map foo mylist) (map bar mylist) (map foobar mylist) If we define mylist as '(1 2 3) , and we run the above functions one at a time, we get: (map foo mylist) =

Delete element from List in Scheme

蓝咒 提交于 2020-01-11 10:52:08
问题 I have list in this form ( (1 3) (2 2) (3 1) (4 5) (5 1))) and I want to delete an item let's say (3 1) So the result will be ( (1 3) (2 2) (4 5) (5 1))) I have written something like this and I do not know why it is not running correctly. (define (deleteItem list item) (cond ((equal? item (car list)) (cdr list)) (cons (car list)(deleteItem(cdr list) item)))) 回答1: There's a built-in function for this, it's called remove: (define lst '((1 3) (2 2) (3 1) (4 5) (5 1))) (remove '(3 1) lst) => '(

The Seasoned Schemer, letcc and guile

≡放荡痞女 提交于 2020-01-10 19:16:12
问题 A few questions here, regarding letcc that is used in The Seasoned Schemer. (define (intersect-all sets) (letcc hop (letrec ((A (lambda (sets) (cond ((null? (car sets)) (hop '()) ((null? (cdr sets)) (car sets)) (else (intersect (car sets) (A (cdr sets))))))) ; definition of intersect removed for brevity (cond ((null? sets) '()) (else (A sets)))))) I think I understand what letcc achieves, and that is basically something like catch and throw in ruby (and seemingly CL), which basically means a

The Seasoned Schemer, letcc and guile

强颜欢笑 提交于 2020-01-10 19:16:04
问题 A few questions here, regarding letcc that is used in The Seasoned Schemer. (define (intersect-all sets) (letcc hop (letrec ((A (lambda (sets) (cond ((null? (car sets)) (hop '()) ((null? (cdr sets)) (car sets)) (else (intersect (car sets) (A (cdr sets))))))) ; definition of intersect removed for brevity (cond ((null? sets) '()) (else (A sets)))))) I think I understand what letcc achieves, and that is basically something like catch and throw in ruby (and seemingly CL), which basically means a

The object ___ is not applicable [duplicate]

醉酒当歌 提交于 2020-01-10 05:56:09
问题 This question already has answers here : “application: not a procedure” in binary arithmetic procedures (1 answer) Getting every nth atom using scheme does not pick up the last atom (3 answers) Closed 5 years ago . Hi I'm writing something that grabs every third element after the first element. However I can't test the logic due to ";The object (a b c d e f g) is not applicable." The code is below, atom? checks if it's a list, listful is defined as an empty list. (DEFINE (threes var) (if(atom

How to remove all the duplicates in a list using scheme (only abstract list functions allowed)

你说的曾经没有我的故事 提交于 2020-01-10 04:36:05
问题 I know how to write this in an recursive way. (define (removed2 lst) (cond [(empty? lst) empty] [(not (member? (first lst) (rest lst))) (cons (first lst) (removed2 (rest lst)))] [else (removed2 (rest lst))])) so (removed2 (list 1 1 1 2 2 2 3 3 3 3 3 3)) gives (list 1 2 3) However, how do you rewrite it only using abstract functions (filter, foldr, map, and build-list)? I tried to use filter but it just doesn't work. 回答1: It's possible to use foldr for this, the trick is knowing what to write

How to recursively go through list of lists and combine the lists in different ways

佐手、 提交于 2020-01-07 08:41:11
问题 This is a follow-up to this question. I have lists or "records" that are appended together into an empty list, that are each in the format (Matthew (AL 21 32)) . I am now trying to write a function that would use fetchRecord in order to find the desired record and then multiply the two numbers inside the record. However, my current code works only if I am getting the name on the first record but it returns an empty list for any record after that. Here is my code: (define (Mult_Num name) (cond

Combine two lists of 3 characters into 3 pairs

 ̄綄美尐妖づ 提交于 2020-01-07 07:48:09
问题 I'm having a little trouble with this. Basically, I need a procedure comb that takes two lists (comb '(a b c) '(1 2 3) and returns ('a 1)('b 2)('c 3) . I came up with a part of the cod which returns the first pair (define some-letters '(a b c)) (define some-nums '(1 2 3)) (define x (first (foldr cons empty some-letters))) (define y (first (foldr cons empty some-nums))) (define (comb list1 list2) (cond [(empty? list1) empty] [(empty? list2) empty] [else (list x y)])) Now, I tinkered around a

How to get system date in R5Rs in Scheme/DrRacket

守給你的承諾、 提交于 2020-01-07 06:46:21
问题 In DrRacket IDE, I was able to get the system date in the following manner when the language setting was 'Swindle': (define currentMonth 0) (let ((date (seconds->date (current-seconds)))) (set! currentMonth (date-month date)) ) Now, I need to do the same in R5Rs, but not sure how to. May I please seek your advise/help on this.. Thank you! 回答1: There is no date-time support in R5RS. The procedures current-seconds , seconds->date and date-month should be available in the R5RS implementation of

Deleting Second last ATOM

这一生的挚爱 提交于 2020-01-06 13:52:58
问题 I am trying to delete second last ATOM from the given list - (define (butSecondLastAtom lst1) (cond ((null? lst1) '()) ((null? (cdr lst1)) lst1) ((null? (cddr lst1)) (cond((not(pair? (car lst1))) (cdr lst1)) (else (cons(butLastAtom (car lst1)) (cdr lst1))))) (else (cons (car lst1) (butSecondLastAtom(cdr lst1)))))) (define (butLastAtom x) (cond ((null? (cdr x)) (cond ((not(pair? (car x))) '()) (else (cons (butLastAtom(car x)) '())))) (else (cons (car x) (butLastAtom(cdr x)))))) This code do