scheme

What is the difference between 1 and '1 in Lisp?

懵懂的女人 提交于 2019-12-02 17:56:52
I had never really thought about whether a symbol could be a number in Lisp, so I played around with it today: > '1 1 > (+ '1 '1) 2 > (+ '1 1) 2 > (define a '1) > (+ a 1) 2 The above code is scheme, but it seems to be roughly the same in Common Lisp and Clojure as well. Is there any difference between 1 and quoted 1? Well, they are in fact very different. '1 is however precisely the same as (quote 1) . (car ''x) evaluates to the symbol 'quote'. 1 is an S-expression, it's the external representation of a datum, a number 1. To say that 1 is a 'number-object' or an S-expression to enter that

a function median in Scheme

筅森魡賤 提交于 2019-12-02 17:41:42
问题 I am new to Scheme and I am using Dr.Racket to try to find the median of the list. If the length of list L is odd, the function median returns the median element in the list. If the length of L is even, the function median returns 0. example (median ‘(1)) returns 1 (median ‘(1 2)) returns 0 (median ‘(1 2 3)) returns 2 (median ‘( 1 2 3 4) returns 0 i am only allowed to use - null? - car - cdr - else - = - + - median - cond - if - user defined names (for my variables) - integer literals -

Lisp/Scheme interpreter without Emacs?

≡放荡痞女 提交于 2019-12-02 17:41:28
I've been wanting to teach myself Lisp for a while. However, all the interpreters of which I've heard involve some flavor of emacs. Are there any command line interpreters, such that I could type this into the command line: lispinterpret sourcefile.lisp just like I can run perl or python. While I'd also like to become more familiar with Emacs (if only not to be frustrated when I work with somebody who uses Emacs), I'd rather decouple learning Emacs from learning Lisp. Edit: I actually want to follow SICP which uses Scheme, so an answer about Scheme would be more useful. I'm just not that

Lisp as a Scripting Language in a C++ app [closed]

江枫思渺然 提交于 2019-12-02 17:34:20
Hey, I've been looking at the possibility of adding a scripting language into my framework and I heard about Lisp and thought I would give it a go. Is there a VM for Lisp like Lua and Python or am I in the wrong mindset. I found CLISP here, http://clisp.cons.org/ , but am not sure if this is what I am looking for. Can anyone point me in the right direction? CLISP is just one implementation of Common Lisp. It's a very good implementation, and it does have some support for being embedded in other (C-based) programs, but that's not its focus and it's GPLed, which may or may not be a deal-breaker

How to determine if a list has an even or odd number of atoms

心已入冬 提交于 2019-12-02 17:32:18
问题 tScheme novice question: I need to determine if a list contains an even or odd amount of atoms using recursion. I know the easy way is to get list length and determine if it is even or odd, but I would like to see hows it's done using recursion. (oddatom (LIST 'x 'y 'v 'd 'r 'h 'y)) should return #t , while (oddatom '((n m) (f p) l (u k p))) should return #f appreciate the help. 回答1: Here's my version of the solution: (define (oddatom? lst) (let recur ((odd #f) (x lst)) (cond ((null? x) odd)

How does code written in one language get called from another language

廉价感情. 提交于 2019-12-02 17:21:18
This is a question that I've always wanted to know the answer, but never really asked. How does code written by one language, particularly an interpreted language, get called by code written by a compiled language. For example, say I'm writing a game in C++ and I outsource some of the AI behavior to be written in Scheme. How does the code written in Scheme get to a point that is usable by the compiled C++ code? How is it used by the C++ source code, and how is it used by the C++ compiled code? Is there a difference in the way it's used? Related How do multiple-languages interact in one project

Scheme contract violation in DrRacket

青春壹個敷衍的年華 提交于 2019-12-02 17:12:45
问题 I am following Brian Harvey’s SICP lectures at archive.org I am using the DrRacket v7.4 IDE to write my Scheme code. At 06:39 Professor Brian Harvey shows how to select the first character of a string. When I follow this method exactly I do not get the expected result, as shown below. Why might that be? My code looks like this: # lang scheme (first 'hello) Expected result: h Error message: first: contract violation expected: (and/c list? (not/c empty?)) given: hello 回答1: While it is the same

iOS自动打包并发布脚本 

江枫思渺然 提交于 2019-12-02 16:53:31
iOS自动打包并发布脚本 本文最终实现的是使用脚本打 Ad-hoc 包,并发布测试,当然稍微修改一下脚本参数就可以打其他类型的 ipa 包了。另外该脚本还实现了将生成的 ipa 包上传至蒲公英进行测试分发。文中内容包括: xcodebuild 简介 使用xcodebuild和xcrun打包签名 将打包过程脚本化 xcodebuild 简介 xcodebuild 是苹果提供的打包项目或者工程的命令,了解该命令最好的方式就是使用 man xcodebuild 查看其 man page. 尽管是英文,一定要老老实实的读一遍就好了。 DESCRIPTION xcodebuild builds one or more targets contained in an Xcode project, or builds a scheme contained in an Xcode workspace or Xcode project. Usage To build an Xcode project, run xcodebuild from the directory containing your project (i.e. the directory containing the name.xcodeproj package). If you have multiple projects in

Implementing “Accumulate” Function in Scheme

荒凉一梦 提交于 2019-12-02 16:49:55
问题 I've been hung on trying to implement an Accumulate function for a couple weeks, now. I have properly implemented a "Map" function, that iterates across a list and runs a function on each element. I am using this function to implement "Accumulate" (define accumulate (lambda (op base func ls) (if(null? ls) ls (cond (not (null? (cdr ls)) (op base (map func ls) (accumulate op base func (cdr ls)))) (op base (map func ls) (op base (func(car ls)))) ) ))) ;It gets to a point (the last element) after

scheme sort list diffent criteria

最后都变了- 提交于 2019-12-02 16:18:20
问题 I have a finite list of quadruples, e.g. (list (list 1 3 5 5) (list 2 3 4 9) (list 3 4 4 6)(list 4 7 10 3)). I denote each of the elements by (a1 a2 a3 a4). Please help me to write a sorting function which provides a "increasing" list created according to the following criteria: the numbers a2, later the difference (a3 - a4), and later the numbers a3. Please help if you can. 回答1: As far as I can tell, your ordered criteria are the order in which to sort. If this is the case, then the