r5rs

Is it possible to “extend” a function / lambda / macro in Scheme?

最后都变了- 提交于 2019-12-22 07:12:08
问题 For example: if I want the function equal? recognize my own type or record, can I add a new behavior of equal? ? without erasing or overwriting the old one? Or for example if I want to make the function "+" accept also string? 回答1: Rather than using import , a better solution is to keep track of the original function by let -binding it. It's also better to check that the type of the argument is a string, rather than that it is not a number. Using both of these approaches means that it's

Is it possible to “extend” a function / lambda / macro in Scheme?

本秂侑毒 提交于 2019-12-22 07:10:02
问题 For example: if I want the function equal? recognize my own type or record, can I add a new behavior of equal? ? without erasing or overwriting the old one? Or for example if I want to make the function "+" accept also string? 回答1: Rather than using import , a better solution is to keep track of the original function by let -binding it. It's also better to check that the type of the argument is a string, rather than that it is not a number. Using both of these approaches means that it's

R5RS Scheme input-output: How to write/append text to an output file?

只谈情不闲聊 提交于 2019-12-20 02:56:14
问题 What is a simple way to output text to file in a R5RS compliant version of Scheme? I use MIT's MEEP (which uses Scheme for scripting) and I want to output text to file. I have found the following other answers on Stackoverflow: File I/O operations - Scheme How to append to a file using Scheme Append string to existing textfile [sic] in IronScheme But, they weren't exactly what I was looking for. 回答1: The answers by Charlie Martin, Ben Rudgers, and Vijay Mathew were very helpful, but I would

A “pure” scheme implementation (R5RS) of SHA256?

杀马特。学长 韩版系。学妹 提交于 2019-12-18 11:13:46
问题 I can use SHA256 in Scheme using external libraries (Java, C or system dependent) or using a specific Scheme implementation (like Chicken e.g.), but I wonder if there is a "pure" scheme implementation. 回答1: I wrote an implementation today. Alas, R5RS has neither bytevectors nor binary I/O, so this uses the R7RS APIs for bytevectors and binary I/O. It should be easy to bridge those APIs to your Scheme implementation's native APIs (for example, I actually tested my implementation on Racket and

ANTLR resolving non-LL(*) problems and syntactic predicates

99封情书 提交于 2019-12-18 05:27:04
问题 consider following rules in the parser: expression : IDENTIFIER | (...) | procedure_call // e.g. (foo 1 2 3) | macro_use // e.g. (xyz (some datum)) ; procedure_call : '(' expression expression* ')' ; macro_use : '(' IDENTIFIER datum* ')' ; and // Note that any string that parses as an <expression> will also parse as a <datum>. datum : simple_datum | compound_datum ; simple_datum : BOOLEAN | NUMBER | CHARACTER | STRING | IDENTIFIER ; compound_datum : list | vector ; list : '(' (datum+ ( '.'

(SCHEME) Number -> English List

依然范特西╮ 提交于 2019-12-13 19:28:08
问题 Okay. So I'm wondering how to create a function that will turn a random number into its english word component. Such as (1001 -> '(one thousand one) or 0 -> '(zero) and (number-name factorial 20 -> ’(two quintillion four hundred thirty two quadrillion nine hundred two trillion eight billion one hundred seventy six million six hundred forty thousand)) I worked with a previous user on stackoverflow to get something that turned a long number into 3 part digits (1,341,100 is one million, 341

How to 'display' multiple parameters in R5RS Scheme

╄→尐↘猪︶ㄣ 提交于 2019-12-12 08:59:23
问题 In R5RS Scheme how do you display multiple parameters, with a single call? my implementation below works, but adds extra parentheses and spaces. #!/usr/bin/env racket #lang r5rs (define (display-all . rest) (display rest)) (display-all "I " "have " "a " "lovely " "bunch " "of " "coconuts\n") results in owner@K53TA:~$ ./Template.ss (I have a lovely bunch of coconuts ) 回答1: Simplest: (define (display-all . vs) (for-each display vs)) Note the use of for-each instead of map - for-each is the same

SCHEME Mutable Functions

别来无恙 提交于 2019-12-12 03:52:51
问题 I've been self-teaching myself Scheme R5RS for the past few months and have just started learning about mutable functions. I've did a couple of functions like this, but seem to find my mistake for this one. (define (lst-functions) (let ((lst '())) (define (sum lst) (cond ((null? lst) 0) (else (+ (car lst) (sum (cdr lst)))))) (define (length? lst) (cond ((null? lst) 0) (else (+ 1 (length? (cdr lst)))))) (define (average) (/ (sum lst) (length? lst))) (define (insert x) (set! lst (cons x lst)))

Pairing 2 lists Scheme

六月ゝ 毕业季﹏ 提交于 2019-12-11 07:23:52
问题 SCHEME/Racket/R5RS Attempting to make a recursive procedure that pairs 2 lists of the same size. Just cant get the recursive call right. This is what I have and I am stuck. (define (pairs list1 list2) (if (or (null? list1) (null? list2)) '() (cons (car list1) (car list2)) )) Test Case: (pairs '(1 2 3) '(a b c)) Desired Output: ((1 . a) (2 . b) (3 . c)) Current Output: (1 . a) 回答1: You just have to cons the current result to the recursive call of the procedure, and that's it! (define (pairs

add1 function from scheme to R5RS

自古美人都是妖i 提交于 2019-12-10 23:25:13
问题 I've written some code but it's not working because the add1 function I used in Scheme is not working with R5RS. What can replace add1 in R5RS? 回答1: The procedure add1 is very simple, you can implement it yourself: (define (add1 x) (+ x 1)) 回答2: late answer but an alternative is (making use of lambdas) .. (define add1 (lambda (x) (+ x 1))) 来源: https://stackoverflow.com/questions/13292094/add1-function-from-scheme-to-r5rs