scheme

Collection of Great Applications and Programs using Macros

泪湿孤枕 提交于 2019-12-17 17:28:19
问题 I am very very interested in Macros and just beginning to understand its true power. Please help me collect some great usage of macro systems. So far I have these constructs: Pattern Matching: Andrew Wright and Bruce Duba. Pattern matching for Scheme, 1995 Relations in the spirit of Prolog: Dorai Sitaram. Programming in schelog. http://www.ccs.neu.edu/home/dorai/schelog/schelog.html Daniel P. Friedman, William E. Byrd, and Oleg Kiselyov. The Reasoned Schemer. The MIT Press, July 2005 Matthias

Implement yield and send in Scheme

痞子三分冷 提交于 2019-12-17 16:23:12
问题 I'm trying to port yield and yield from from Python to Scheme. Here is an implementation I've done: (define (coroutine routine) (let ((current routine) (status 'new)) (lambda* (#:optional value) (let ((continuation-and-value (call/cc (lambda (return) (let ((returner (lambda (value) (call/cc (lambda (next) (return (cons next value))))))) (if (equal? status 'new) (begin (set! status 'running) (current returner)) (current (cons value returner))) (set! status 'dead)))))) (if (pair? continuation

Getting every nth atom using scheme does not pick up the last atom

吃可爱长大的小学妹 提交于 2019-12-17 14:56:41
问题 The program is suppose to pick out every third atom in a list. Notice that the last atom 'p' should be picked up, but its not. Any suggestions as to why the last atom is not being selected. (define (every3rd lst) (if (or (null? lst) (null? (cdr lst))) '() (cons (car lst) (every3rd (cdr(cdr(cdr lst))))))) (every3rd '(a b c d e f g h i j k l m n o p)) Value 1: (a d g j m) Thanks 回答1: You're missing a couple of base cases: (define (every3rd lst) (cond ((or (null? lst) (null? (cdr lst))) lst) (

How to Reverse a List?

大城市里の小女人 提交于 2019-12-17 11:08:52
问题 What is the function to a list in Scheme? It needs to be able to handle nested lists. So that if you do something like (reverse '(a (b c d) e)) you'll get (e (b c d) a) as the output. How should I approach this problem? I'm not just looking for an answer, but something that will help me learn. 回答1: (define (reverse1 l) (if (null? l) nil (append (reverse1 (cdr l)) (list (car l))) ) ) Explanation: Rules: 1. If list is empty, then reverse list is also empty 2. else behind reverse tail of the

Selenium chrome配置代理Python版

喜夏-厌秋 提交于 2019-12-17 05:26:48
环境: windows 7 + Python 3.5.2 + Selenium 3.4.2 + Chrome Driver 2.29 + Chrome 58.0.3029.110 (64-bit) Selenium官方给的Firefox代理配置方式并不起效,也没看到合适的配置方式,对于Chrome Selenium官方没有告知如何配置,但以下两种方式是有效的: 1. 连接无用户名密码认证的代理 chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument('--proxy-server=http://ip:port') driver = webdriver.Chrome(chrome_options=chromeOptions) 2. 有用户名和密码的连接 from selenium import webdriverdef create_proxyauth_extension(proxy_host, proxy_port, proxy_username, proxy_password, scheme='http', plugin_path=None): """Proxy Auth Extension args: proxy_host (str): domain or ip address, ie proxy

关于Android路由的实现

岁酱吖の 提交于 2019-12-16 19:02:57
  先说一下背景,目前有需求从外部包括其他应用和WEB跳转到我们自己的APP,就这么个简单的需求……   要实现这种外部跳转的功能,我们可以理解为打算跳转的一方有多少方式通知到APP进行相对的响应行为。所以,如果是应用之间的跳转,则有多种,你可以直接通过包名和具体的类名去打开已经exported=true的Activity,又或者直接通过Android的广播通知进行相关的APP,又或者通过自定义的URL去打开应用。但是如果涉及到Web打开外部应用的话,目前只有一种办法,那就是自定义应用的URL进行拦截,系统会自动调起相应的组件响应这个URL。   但是,要做这种需求,很少会仅仅是完成对外部的支持而已,通常也要进行一定的内部逻辑跳转映射。所以要做这种需求通常分为两个种,一种是对内的(应用内部自己的跳转逻辑),一种对外的(其他应用以及Web跳转逻辑)。   我们先说一下对外的情形,由于考虑到统一性,我们目前只有URL这种手段可以使用了。下面我们一一来说    1、对外跳转说明   1.1、关于URL的说明。   首先,我们得了解一下URL,这里直接引用 https://en.wikipedia.org/wiki/URL 的说明。为了方便说明,我稍稍修改一下,大概的格式如下:    scheme: [ // host [ :port ]][ /path ][? query ][#

Why is (quote '“foo”) valid syntax in Scheme?

↘锁芯ラ 提交于 2019-12-14 04:03:43
问题 Why does (quote '"foo") go through the Scheme interpreter? It should be syntactically redundant or wrong based on how expressions are constructed in Scheme. quote is used whenever one wants to use a symbol without Scheme thinking it's a variable and strings aren't valid symbols so why is the abbreviation for the quote operator valid when prefixed to strings? Oddly enough (quote '"foo") returns (quote "foo") . Redundancy? Another strange experiment (symbol? '"foo") is evaluated to #f so that

`or` function in Scheme misbehaving

醉酒当歌 提交于 2019-12-14 03:59:52
问题 I am trying to write an or function in Scheme (define or (lambda (p q) p p q)) If I do (or #t #f) I get #f . What is the problem in what I am doing? I saw λpq.ppq in a video on youTube. 回答1: The correct Lambda Calculus definitions are (define or (lambda (p q) (p p q))) ; (or p q) = {p AND p} OR {{NOT p} AND q} (define xor (lambda (p q) (p (not q) q))) ; (xor p q) = {p AND {NOT q}} OR {{NOT p} AND q} (define not (lambda (t) (lambda (p q) (t q p)))) ; ((not t) p q) = (t q p) (note the parens!).

Scheme merge two lists into one

╄→гoц情女王★ 提交于 2019-12-14 03:53:19
问题 how to design a function that merge two lists into one list. the first element of first list will be the first element of the new list and the first element of the second list will be the second element of the new list (a,b,c,d,e,f) (g,h,i) will be (a,g,b,h,c,i,d,e,f,) 回答1: The procedure you're trying to implement is known as interleave or merge . Because this looks like homework, I can't leave you a straight answer, instead I'll point you in the right direction; fill-in the blanks: (define

Buffered I/O in Chicken Scheme?

喜欢而已 提交于 2019-12-14 03:46:20
问题 Racket has the nice read-bytes-async! function, which I believe exists in every other programming language in the world. It reads what it can from an input stream, without blocking, into a buffer, returning the number of bytes written. Said function seems like an absolutely essential function for efficiently implementing, say, the Unix cat tool, yet Chicken Scheme seems to lack any such function. Of course, I can use (read-byte) and (write-byte) , but that is slow and eats up all my CPU. Even