scheme

How do I define a sub environment in scheme?

这一生的挚爱 提交于 2019-12-04 17:31:27
I am just hacking around with Scheme (mit-scheme) and I have just figured out how you change the environment, so that '+' becomes a symbol for the equivalent procedure of the '-' operator. Example (environment-define user-initial-environment '+ -) (eval (+ 3 2) user-initial-environment) => 1 I was just wondering if there were a simple way to deal with environments as variables so when I input an environment into eval, like so (eval <exp> user-initial-environment) I don't have to use 'user-initial-environment'. So I can 'play' with different environments for a function. (eval <exp> env) Where

Are Lisp forms and Lisp expressions same thing?

谁说我不能喝 提交于 2019-12-04 16:54:57
问题 Some literature say "the first subform of the following form..." or "to evaluate a form..." while some other literature say "To evaluate an expression...", and most literature seem to use both terms. Are the two terms interchangeable? Is there a difference in meaning? 回答1: The definitions and uses of these terms vary by Lisp dialect and community, so there is no clear answer to your question for Lisps in general. For their use in Common Lisp, see Rainers detailed answer. To give a short

Hybrid App: 对比UIWebView和WebKit实现JavaScript与Native交互

こ雲淡風輕ζ 提交于 2019-12-04 16:06:01
一、简介 在前面一篇文章中讲到过实现JavaScript与Native交互的方式有一种就是使用原生内嵌webView。在iOS8之前,开发者只能使用苹果提供的UIWebView类来加载URL或者HTML网页视图,然后通过设置代理,在回调函数中拦截并处理自定义交互事件,功能十分有限,通常只是作为一个辅助视图使用。在iOS8之后,苹果对这方面的技术进行了重构和优化,推出了一个新的框架WebKit。WebKit提供了Native与JavaScript交互的方法,整个框架的结构很清晰,对外暴露的接口友好实用,极大地方便了开发者实现网页视图和的Native交互。并且,WebKit框架采用导航堆栈的模式来管理网页视图的跳转,对于网页视图的管理和渲染,开发者更加容易管控。慢慢地,咱来比较这两种webView的使用区别。 二、UIWebView 1、UIWebView的详细构成 UIWebView的类构成之:属性 //id类型,遵守UIWebViewDelegate协议 @property (nullable, nonatomic, assign) id <UIWebViewDelegate> delegate //只读属性,webView内部的滚动视图 @property (nonatomic, readonly, strong) UIScrollView *scrollView //只读属性

The Little Schemer - Where to start?

醉酒当歌 提交于 2019-12-04 16:03:49
问题 I just cracked open The Little Schemer, and I feel like I'm missing something. The first question asks "Is it true that this is an atom?", but I do not see any definition of what an atom is. I suppose I can derive what an atom is by the answers to the questions, but then it goes on to ask what is the car of l, and what is the cdr of l, and I have no idea what is being asked. Is the purpose of the book to discover what the questions mean by reading the answers, or is there some basic knowledge

Arbitrary computation in Scheme macro

隐身守侯 提交于 2019-12-04 16:00:17
Scheme macros, at least the syntax-case variety, are said to allow arbitrary computation on the code to be transformed. However (both in the general case and in the specific case I'm currently looking at) this requires the computation to be specified in terms of recursive functions. When I try various variants of this, I get e.g. main.scm:32:71: compile: unbound identifier in module (in the transformer environment, which does not include the run-time definition) in: expand-vars (The implementation is Racket, if it matters.) The upshot seems to be that you can't define named functions until

Simplest example of need for “unification” in type inference

随声附和 提交于 2019-12-04 14:28:41
I'm trying to get my head around how type inference is implemented. In particularly, I don't quite see where/why the heavy lifting of "unification" comes into play. I'll give an example in "pseudo C#" to help clarify: The naive way to do it would be something like this: Suppose you "parse" your program into an expression tree such that it can be executed with: interface IEnvironment { object lookup(string name); } interface IExpression { // Evaluate this program in this environment object Evaluate(IEnvironment e); } So something like "Multiplication" might be implemented with: class Multiply :

Scheme - Map function for applying a function to elements in a nested list

佐手、 提交于 2019-12-04 14:28:06
问题 I'm trying to write a mapping function in scheme that applies a function to each value in a nested list. For example, (map number? '(3 (2 A) 2 Z) should return (#t (#t #f) #t #f) Here's what I have so far: (define (map fun lst) (if (null? lst) '() (if (list? (car lst)) (cons (map fun (car lst)) (map fun (cdr lst))) (cons (fun (car lst)) (map fun (cdr lst)))))) It works if the nested list is at the front of the list. For example (map number? '((3 A) 2 Z)) correctly returns ((#t #f) #t #f) The

Changing a function into CPS style

喜你入骨 提交于 2019-12-04 13:02:42
We were asked to write a procedure that when given a list it will replace the first occurrence of a given element and only the first, but the catch is to write in CPS style. We are unable to turn it to CPS style written procedure that is given a success-cont and fail-cont.. If anyone is willing to give it a try we will really appreciate it :] The procedure we have (graciously provided by answers here ): (define (replace-one list old new) (cond ((pair? list) (let ((next (replace-one (car list) old new))) (cons next (if (equal? next (car list)) ; changed? (replace-one (cdr list) old new) ; no,

Scheme, When to use Symbols instead of Strings?

时间秒杀一切 提交于 2019-12-04 09:39:36
I apologize in advance for my primitive english; i will try my best to avoid grammatical errors and such. Two weeks ago i decided to freshen my knowledge of Scheme (and its enlightnings) whilst implementing some math material i got between hands, specifically, Regular Languages from a course on Automata theory and Computation in which i am enrolled. So far, i've been representing alphabets as lists of symbols instead of lists of chars because i want to have letters of variable size. lists of strings because i somewhat feel thats unelegant. I'm inexperienced and would like to know your opinion

creating permutation of a list in scheme

♀尐吖头ヾ 提交于 2019-12-04 09:39:15
I'm trying to write a function that creates the permutation of a list using just the basic list constructs (cons, empty, first, rest). I'm thinking of inserting the first value of the list everywhere in the recursive call of the rest of the list, but I'm having some trouble with my base case. My code: (define (permutation lst) (cond [(empty? lst) (cons empty empty)] [else (insert_everywhere (first lst) (permutation (rest lst)))])) (permutation (list 1 2)) gives me (list 1 2 empty 2 1 empty). Is there anything I can do to create a placeholder (such as empty) between the different combinations