scheme

how to convert a list to num in scheme?

北城以北 提交于 2019-12-31 04:23:05
问题 like convert (1 2 3 4) to 1234~ 回答1: The problem is characterized by coalescing a list into a single value, strongly suggesting use of a fold: (define (fold-left op initial items) (define (loop result rest) (if (null? rest) result (loop (op result (car rest)) (cdr rest)))) (loop initial items)) (define (list->num list) (fold-left (lambda (value digit) (+ (* value 10) digit)) 0 list)) (list->num '(1 2 3 4)) ;Value: 1234 回答2: This sounds like a homework question... Think about powers of ten and

A function which will determine that if a passed in list follows an A B pattern

和自甴很熟 提交于 2019-12-31 04:13:09
问题 (define fun4 (lambda ( ls) (cond ((null? ls ) #f) (cons (((eqv? 'a (car ls))) && ((eqv? 'b (cdr ls))))) (else (pattern2 cdr ls))))) In this it showing error - procedure application: expected procedure, given: #t (no arguments), What is the erroe in my code. Is logic is fine ??? 回答1: There are many, many errors in your solution. Let's see what's wrong in each of the conditions: The base case of the recursion (empty list) is wrong: an empty list is the exit of the recursion, and it means that

How to take intersection of pairs from two lists in scheme?

↘锁芯ラ 提交于 2019-12-31 04:08:08
问题 I am using this script from The little schemer, to get intersection of two sets. But I am getting unbound identifier error at 'member?', can anyone please tell what's wrong with it: (define intersect (lambda (set1 set2) (cond ((null? set1) (quote ())) ((member? (car set1) set2) (cons (car setl) (intersect (cdr set1) set2))) (else (intersect (cdr setl) set2))))) I was missing this function above: (define member? (lambda (a lat) (cond ((null? lat) #f) (else (or (eq? (car lat) a) (member? a (cdr

seek for some explanation on SICP exercise 1.5

谁说胖子不能爱 提交于 2019-12-30 17:55:22
问题 The question can be found here. In the book, I found one description of normal order evaluation was: "An alternative evaluation model would not evaluate the operands until their values were needed. Instead it would first substitute operand expressions for parameters until it obtained an expression involving only primitive operators, and would then perform the evaluation." I also found another description in short: "fully expand and then reduce". In the exercise, I thought the definition of p

How to change printing behaviour in DrRacket for R6RS to print results like with #lang racket

江枫思渺然 提交于 2019-12-30 11:09:10
问题 When I'm running a program in the IDE, version 5.3.5--2013-06-18(-/f), for #lang racket , eg. #lang racket (+ 4 5) (/ 10 2) When pressing Run > , the interaction window gets "9\n5\n" printed to the interactions window. The same version as R6RS #!r6rs (import (rnrs base)) (+ 4 5) (/ 10 2) It seems I get no output when pressing Run > when language is R6RS . Is there anywhere I can change this behavior, in Preferences perhaps? 来源: https://stackoverflow.com/questions/19624049/how-to-change

Writing portable scheme code. Is anything “standard” beyond R5RS itself?

一曲冷凌霜 提交于 2019-12-30 05:54:45
问题 I'm learning scheme and until now have been using guile. I'm really just learning as a way to teach myself a functional programming language, but I'd like to publish an open source project of some sort to reenforce the study— not sure what yet... I'm a web developer, so probably something webby. It's becoming apparent that publishing scheme code isn't very easy to do, with all these different implementations and no real standards beyond the core of the language itself (R5RS). For example, I'm

Why doesn't C# have lexically nested functions?

醉酒当歌 提交于 2019-12-30 01:08:06
问题 Why might the C# language designers not have included support for something like this (ported from Structure and Interpretation of Computer Programs, second ed., p. 30): /// <summary>Return the square root of x.</summary> double sqrt(double x) { bool goodEnough(double guess) { return Math.Abs(square(guess) - x) < 0.001; } double improve(double guess) { return average(guess, x / guess); } double sqrtIter(double guess) { return goodEnough(guess) ? guess : sqrtIter(improve(guess)); } sqrtIter(1

Why doesn't C# have lexically nested functions?

北城以北 提交于 2019-12-30 01:08:05
问题 Why might the C# language designers not have included support for something like this (ported from Structure and Interpretation of Computer Programs, second ed., p. 30): /// <summary>Return the square root of x.</summary> double sqrt(double x) { bool goodEnough(double guess) { return Math.Abs(square(guess) - x) < 0.001; } double improve(double guess) { return average(guess, x / guess); } double sqrtIter(double guess) { return goodEnough(guess) ? guess : sqrtIter(improve(guess)); } sqrtIter(1

Can call-with-current-continuation be implemented only with lambdas and closures?

我们两清 提交于 2019-12-30 00:32:22
问题 Does anyone know if call/cc can be implemented with just lambdas and closures? It seems that call/cc interrupts the program's flow (like an exception) but lambdas and closures can't do that. Therefore I think call/cc can't be implemented via lambdas and closures. Any more ideas? 回答1: The question is not particularly clear, since what exactly does "implemented with just lambdas and closures" mean? In any case, continuations can be used in any language with closures by manually writing in

iOS微信分享功能简单实现

我只是一个虾纸丫 提交于 2019-12-29 20:37:06
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 文/老坛泡菜(简书作者) 原文链接:http://www.jianshu.com/p/7a2f49c654df 著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。 PS:此文以简单实现功能为主,不足之前还望指点,大神勿喷. 在此之前如何申请微信认证的Key就不说了,公司一般会有人搞 1.首先下载微信SDK: 微信SDK下载地址 (更多关于微信SDK信息文档请访问官方网站: 微信开放平台 ) 2.导入微信SDK 将下载下来的SDKExport文件夹导入到工程,其中包含3个核心文件libWeChatSDK.a WXApi.h WXApiObject.h(强烈建议大家看看read-me文件) 3.在工程Build Phases -> Link Binary With Libraries 链接以下动态库和框架文件 SystemConfiguration.framework libz.dylib libsqlite3.0.dylib CoreTelephony.framework 4.使用SDK注册你的APP 建议在 AppDelegate 此方法中注册,导入 import "WXApi.h" - (BOOL)application:(UIApplication *)application