scheme

Why all the lambdas in The Little Schemer?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 20:37:31
After learning a bit of Scheme from SICP, I started reading The Little Schemer (which I find quite entertaining) and am about one fourth done. I noticed that I can write many (most? all?) solutions without using lambda whereas The Little Schemer always uses them. For example, the very first definition is (define atom? (lambda (x) (and (not (pair? x)) (not (null? x))))) which, unless I am mistaken, can be written more simply as (define (atom? x) (and (not (pair? x)) (not (null? x)))) Am I missing something fundamental if I write lambda-less solutions? Originally, define had a single syntax, to

HTML学习(17)URL

匿名 (未验证) 提交于 2019-12-02 20:32:16
HTML 统一资源定位器(Uniform Resource Locators) URL - 统一资源定位器 Web浏览器通过URL从Web服务器请求页面。 scheme :// host.domain : port / path / filename 说明: scheme - 定义因特网服务的类型。最常见的类型是 http host - 定义域主机(http 的默认主机是 www) domain - 定义因特网域名,比如 runoob.com :port - 定义主机上的端口号(http 的默认端口号是 80) path - 定义服务器上的路径(如果省略,则文档必须位于网站的根目录中)。 filename - 定义文档/资源的名称 常见的 URL Scheme 以下是一些URL scheme: Scheme 访问 用于... http 超文本传输协议 以 http:// 开头的普通网页。不加密。 https 安全超文本传输协议 安全网页,加密所有信息交换。 ftp 文件传输协议 用于将文件下载或上传至网站。 file 您计算机上的文件。 URL 字符编码 URL 只能使用 ASCII 字符集 . 来通过因特网进行发送。由于 URL 常常会包含 ASCII 集合之外的字符,URL 必须转换为有效的 ASCII 格式。 URL 编码使用 "%" 其后跟随两位的十六进制数来替换非

Data.URI.scheme

匿名 (未验证) 提交于 2019-12-02 20:32:16
<!DOCTYPE html> <html> <body> <!-- Data URI scheme是在RFC2397中定义的,目的是将一些小的数据,直接嵌入到网页中,从而不用再从外部文件载入。 目前,Data URL scheme 支持的类型: data:,文本数据 data:text/plain,文本数据 data:text/html,HTML代码 data:text/html;base64,base64编码的HTML代码 data:text/css,CSS代码 data:text/css;base64,base64编码的CSS代码 data:text/JavaScript,Javascript代码 data:text/javascript;base64,base64编码的Javascript代码 data:image/gif;base64,base64编码的gif图片数据 data:image/png;base64,base64编码的png图片数据 data:image/jpeg;base64,base64编码的jpeg图片数据 data:image/x-icon;base64,base64编码的icon图片数据 --> <img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD"> </body> </html>

Scheme changing tree values

六月ゝ 毕业季﹏ 提交于 2019-12-02 20:23:07
问题 I need to implement a procedure called inverse-tree that receives a tree whose nodes data values are numbers and booleans and returns the equivalent tree whose nodes satisfy the following: If the equivalent node of the original tree is a number, then the resulting tree’s node is −1· that node value If the equivalent node of the original tree is a boolean, then the resulting tree’s node is the logical not of that node value Examples: > (inverse-tree ’()) ’() > (inverse-tree ’(5)) ’(-5) >

What is ' (apostrophe) in Lisp / Scheme?

自闭症网瘾萝莉.ら 提交于 2019-12-02 19:55:47
I am on day 1 hour 1 of teaching myself Scheme. Needless to say, I don't understand anything. So I'm reading The Little Schemer and using this thing: http://sisc-scheme.org/sisc-online.php as an interpreter. I need to use ' in for example (atom? 'turkey) to avoid an "undefined variable" error. The ' , according to the book, is a Common Lisp thing. I have two questions: Is the interpreter I mentioned above a good one? Can you recommend another? I need one that will go well with The Little Schemer . What is ' ? The form 'foo is simply a faster way to type the special form (quote foo) which is to

Creating a partition of a set in Scheme

会有一股神秘感。 提交于 2019-12-02 19:33:07
问题 I'm pretty new to scheme overall and I'm having some issues with figuring out an assignment for school. So please no full answers, just looking for a little insight or a nudge in the right direction so I can figure this out on my own. The problem is as follows: Given a list of numbers, determine whether two subsets can be made from those numbers of equivalent sum and # of items. So for example, if the given set is (1 1) then my program should return #t, otherwise #f. Here is what I have

Finding maximum distance between two points in a list (scheme)

拈花ヽ惹草 提交于 2019-12-02 19:24:20
问题 I'm currently trying to write a function from a list of points that returns the distance from a point p to a point in my point list that is farthest away from p. My list of points are the following: ((2 . 4) (3 . 6) (5 . 12) (-4 . 3) (8.4 . 9) (0 . -1)) I have also made some abstractions to retrieve the general car and cdr (for easier visibility in the code), as well as the car and cdr of the list itself. (define (get-x p) (car p) (define (get-y p) (car p) (define (get-first-point pt-list)

Reverse list in Racket in O(n)

↘锁芯ラ 提交于 2019-12-02 18:22:50
问题 I need to write a recursive function in Scheme which takes a list of atoms and reverses it in linear time. I am only allowed to use define, lambda, cons, car, cdr, cond, let, and null? . Here is what I have so far: (define reverse (lambda (lat) (cond ((null? lat) lat) (else (cons (reverse (cdr lat)) (cons (car lat) '())))))) So when I call the function: (reverse '(a b c d)) I get the following output: '(() (((() 4) 3) 2) 1) Any help would be very much appreciated. 回答1: The problem is that if

How to implement the Observer Design Pattern in a pure functional way?

懵懂的女人 提交于 2019-12-02 18:09:59
Let's say I want to implement an event bus using a OO programming language. I could do this (pseudocode): class EventBus listeners = [] public register(listener): listeners.add(listener) public unregister(listener): listeners.remove(listener) public fireEvent(event): for (listener in listeners): listener.on(event) This is actually the the observer pattern, but used for event-driven control flow of an application. How would you implement this pattern using a functional programming language (such as one of the lisp flavors)? I ask this because if one doesn't use objects, one would still need

Why continuation passing style

て烟熏妆下的殇ゞ 提交于 2019-12-02 18:08:04
In The Scheme Programming Language by Kent Dybvig (4th edition) section 3.4 , he describes very clearly what continuation passing style is. For the why he gives two reasons: pass more than one result to its continuation, because the procedure that implements the continuation can take any number of arguments. CPS also allows a procedure to take separate continuations ..., which may accept different numbers of arguments. Since the first reason can also be done using the values procedure and the second using case-lambda , I'm not clear the advantages of using continuation passing style. Could