scheme

Scheme Error Object Is Not Applicable

北战南征 提交于 2019-12-20 04:22:41
问题 I am writing a Scheme function that detects if a word is in a list of words. My code uses an if statement and memq to return either #t or #f. However, something is causing the first parameter to return the error that the object is not applicable. (define in? (lambda (y xs) ((if (memq( y xs )) #t #f)))) 回答1: Parentheses matter: (define in? (lambda (y xs) (if (memq y xs) #t #f))) so you have double parentheses before if you put memq parameters between parentheses BTW, you can also express this

shareinstall-ios集成方法

耗尽温柔 提交于 2019-12-20 04:03:53
1、产品原理 精确的App安装来源与携带参数安装 :shareInstall的核心价值在于,帮助Android/iOS开发者通过shareInstall提供的sdk,精确的获取app每一次安装的分享(或推广)来源。原理如下:开发者在分享的h5页面上集成 shareInstall web sdk,发布分享链接时在url上动态的拼接任意的自定义参数(如推广渠道号,邀请码等等);当某一终端访问该h5页面时,shareinstall web sdk将同时确定该设备的个性化信息和采集自定义参数,上传至shareInstall服务器, 待用户通过该h5页面安装app后首次打开时(如当前设备已安装该app,将直接拉起该app并传递参数),使用shareInstall Android/iOS sdk从shareInstall服务器再取回暂存的自定义参数。 一键拉起功能:shareInstall通过标准的scheme、universal link 等技术,在app已安装的情况下,从各种浏览器(包括微信、QQ、新浪微博、钉钉等主流社交软件的内置浏览器)拉起app并传递自定义参数,避免重复安装,如没安装则调至appStore或应用宝下载app,下载完毕唤起app的相应页面。 2、iOS SDK集成 1、初始化 1.1 获取shareinstall 的AppKey 登录shareinstall后台管理

List order after duplicate filtering

我怕爱的太早我们不能终老 提交于 2019-12-20 03:15:04
问题 I'm trying to teach myself functional language thinking and have written a procedure that takes a list and returns a list with duplicates filtered out. This works, but the output list is sorted in the order in which the last instance of each duplicate item is found in the input list. (define (inlist L n) (cond ((null? L) #f) ((= (car L) n) #t) (else (inlist (cdr L) n)) )) (define (uniquelist L) (cond ((null? L) '()) ((= 1 (length L)) L) ((inlist (cdr L) (car L)) (uniquelist (cdr L))) (else

Filtering through a list of numbers

余生长醉 提交于 2019-12-20 03:11:35
问题 This is my function for curry: (define (curry g) (lambda(x) (lambda(y) (g x y)))) I'm trying to produce a list of numbers not equal to 1 using the curry function. What I have so far is: (define filter-numbers ((curry filter) ((curry equal?) 1))) But it only produces the list of numbers equal to 1. ex. (filter-numbers (list 1 2 3)) -> (list 1) I want to get (list 2 3) but have no idea how. Can anyone help? 回答1: Try this - is the right approach in Racket, using the built-in curry and filter-not

Applying a symbol as a procedure

ぃ、小莉子 提交于 2019-12-20 03:09:16
问题 Suppose I have a simple symbol: > '+ + Is there any way I can apply that symbol as a procedure: > ((do-something-with '+) 1 2) 3 So that '+ is evaluated to the procedure + ? 回答1: I'm not 100% sure, but would: ((eval '+) 1 2) work? I'm not sure if you need to specify the environment, or even if that works - I'm a Scheme noob. :) 回答2: Lucas's answer is great. For untrusted input you can make a white list of allowed symbols/operators. (define do-something (lambda (op) (cond ((equal? op `+) +) (

Applying a symbol as a procedure

↘锁芯ラ 提交于 2019-12-20 03:08:10
问题 Suppose I have a simple symbol: > '+ + Is there any way I can apply that symbol as a procedure: > ((do-something-with '+) 1 2) 3 So that '+ is evaluated to the procedure + ? 回答1: I'm not 100% sure, but would: ((eval '+) 1 2) work? I'm not sure if you need to specify the environment, or even if that works - I'm a Scheme noob. :) 回答2: Lucas's answer is great. For untrusted input you can make a white list of allowed symbols/operators. (define do-something (lambda (op) (cond ((equal? op `+) +) (

Check for a prime number using recursive helper function

好久不见. 提交于 2019-12-20 02:56:14
问题 I am trying to check if a number is prime using recursion. I was required to use a recursive helper function, but I am not sure how I should implement it. I think I know the algorithm, but I've never tried to use a recursive helper function in Racket. This is my current thoughts: See if n is divisible by i = 2 Set i = i + 1 If i^2 <= n continue. If no values of i evenly divided n , then it must be prime. This is what I have so far... (define (is_prime n) (if (<= n 1) #f (if (= (modulo n 2) 0)

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

Currying a function n times in Scheme

落花浮王杯 提交于 2019-12-20 02:28:23
问题 I'm having trouble figuring out a way to curry a function a specified number of times. That is, I give the function a natural number n and a function fun, and it curries the function n times. For example: (curry n fun) Is the function and a possible application would be: (((((curry 4 +) 1) 2) 3) 4) Which would produce 10. I'm really not sure how to implement it properly. Could someone please give me a hand? Thanks :) 回答1: You can write your own n-curry procedure by repeatedly calling curry :

Scheme Continuation: What's the difference between call 'call/cc' in top level and non-top level?

Deadly 提交于 2019-12-20 02:26:24
问题 This code works as expected: (define saved #f) (cons 'wo (call/cc (lambda (k) (set! saved k) '()))) (saved 'ca!) output (Racket console): '(wo) '(wo . ca!) But when I wrap it in a function and call it, the program never stops. Why? (define (test) (define saved #f) (cons 'wo (call/cc (lambda (k) (set! saved k) '()))) (saved 'ca!)) (test) 回答1: A continuation is all that's left to be done in the execution context where it's saved. In the first case, the continuation is saved when calling cons ,