scheme

Scheme - sum the squares of even-valued elements in a list

十年热恋 提交于 2019-12-29 09:26:12
问题 I want to be able to sum the squares of the even elements in the list, however my current code only sums the elements, not the squares. Does anyone know of any modifications that can be made to make this to sum the squares of the even-valued elements in the list? (define (sum elemList) (if (null? elemList) 0 (+ (car elemList) (sum (cdr elemList))) ) ) My input would be: (sum-evens (list 1 2 3 4)) Output would be: 20 Which is (2*2) + (4*4) . If possible, it would be good to see both a

How to use existing macros - e.g. `let-values` - from a macro expander procedure in Chicken Scheme?

风流意气都作罢 提交于 2019-12-29 09:18:07
问题 How do I call built-in Chicken Scheme macros - specifically let-values in this instance - from my own macros? (define-syntax ... (ir-macro-transformer (lambda (expr inject compare) (let-values (...) ... ... unbound variable: let-values 回答1: This is a bit of a bug I'm afraid. A simple (import-for-syntax chicken) did the trick for me. In CHICKEN 5, this works without such a strange import. 来源: https://stackoverflow.com/questions/38884486/how-to-use-existing-macros-e-g-let-values-from-a-macro

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

Sieve of Eratosthenes Scheme

岁酱吖の 提交于 2019-12-29 08:05:42
问题 I've been searching the web for an implementation of the Sieve of Eratosthenes in scheme and although I came up with a lot of content, none of them seemed to have made it like I need it to be done. The problem is most algorithms either use a static end or use iteration. This paired with my lack of knowledge of the language led me to ask all of you for help. I need an implementation of the Sieve that takes in one argument (number to Sieve until), uses only recursion and has a list of "cons" of

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

What is the exact definition of a Metacircular Interpreter?

安稳与你 提交于 2019-12-29 03:40:06
问题 Is it legal to call a C compiler written in C or a PHP interpreter written in PHP metacircular? Is this definition valid only for languages of a specific type, like Lisp? In short, what are the conditions that an interpreter should satisfy for being called Metacircular? 回答1: A metacircular interpreter is an interpreter written in a (possibly more basic) implementation of the same language. This is usually done to experiment with adding new features to a language, or creating a different

How to undefine a variable in Scheme?

扶醉桌前 提交于 2019-12-28 13:47:30
问题 How to undefine a variable in Scheme? Is this possible? 回答1: In Scheme, variables are defined with either lambda, or one of the various lets. If you want one of them to be 'undefined' then all you need to do is leave the scope that they're in. Of course, that's not really undefining them, it's just that the variable is no longer bound to its previous definition. If you're making top level definitions, using (define), then technically you're defining a function. Since Scheme is functional,

How to undefine a variable in Scheme?

谁说我不能喝 提交于 2019-12-28 13:47:07
问题 How to undefine a variable in Scheme? Is this possible? 回答1: In Scheme, variables are defined with either lambda, or one of the various lets. If you want one of them to be 'undefined' then all you need to do is leave the scope that they're in. Of course, that's not really undefining them, it's just that the variable is no longer bound to its previous definition. If you're making top level definitions, using (define), then technically you're defining a function. Since Scheme is functional,