lisp

How Functional language are different from the language implementation point of view

不羁的心 提交于 2019-12-02 19:29:32
There is the whole new paradigm of "functional programming", which needs a total change of thought patterns compared to procedural programming. It uses higher order functions, purity, monads, etc., which we don't usually see in imperative and object oriented languages. My question is how the implementation of these languages differs from imperative or object oriented languages, with respect to, for example, memory management or internals like pointers etc.. There are functional languages that run on top of the JVM. Does this mean that these languages internally work like the other languages on

Common Lisp Double-Backquote, Unquote, Quote, Unquote sequence?

大兔子大兔子 提交于 2019-12-02 19:08:15
I'm reading Let Over Lambda, which deals with some pretty deeply layered macro authoring. It's fascinating and I'm mostly managing to keep up with it. In Chapter 4 Hoyte implements reader macros for CL-PPCRE match and replace functions, such that you can do things like: (#~m/(foo|bar)\d+/ "Some foo99") ; matches! (#~s/foo(\d+)/bar\1/, "Some foo99") ; "Some bar99 In order to achieve this, we define a macro that uses the double-backquote, since it is actually expanded by a wrapper macro, which needs the quoted value (it returns a lambda form). Within the quasi-quoted list, there is some use of

converting number to string in lisp

醉酒当歌 提交于 2019-12-02 19:07:20
I tried to find a lisp function to convert between numbers and strings and after a little googling I fond a function with the same name. when I entered (itoa 1) SLIME printed: Undefined function ITOA called with arguments (1) . How can I do the conversion? From number to string: (write-to-string 5) "5" you may transform a string to any numerical notation: (write-to-string 341 :base 10) "341" From string to number: (parse-integer "5") 5 with some trash (parse-integer " 5 something not a number" :junk-allowed t) 5 Or use this: (read-from-string "23 absd") 23 A heavyweight solution is to use

How to do Pattern Matching in Common Lisp

我与影子孤独终老i 提交于 2019-12-02 18:51:01
I have no idea if there exists a pattern matching function for Common Lisp, nevertheless I have to make my own function. I have no idea about Lisp. Can somebody give heads-up on learning Lisp and most importantly, how to go about doing pattern matching in Lisp. I will have to pass a pattern and a fact and say if they match. An example would be (heroes (hitpoints=hp) (mana=m)) should match (Morphling (hitpoints 435) (mana 260)) it should also be able to also do numeric comparisons of if a number is greater or lesser. Like if another heroes mana is less that Morphling. Simple pattern matching

在 LispBox 中安装 aserve 的最简单办法--使用 quicklisp

依然范特西╮ 提交于 2019-12-02 18:31:03
在 LispBox 中安装 aserve 的最简单办法--使用 quicklisp 终于解决一个困扰很久的问题,以前一直没办法正确安装 aserve (就是那个免费版的 portableaserve),不是这里报错就是那里报错,总是提示流相关的问题,当时用 quicklisp 安装了一些流,但是最终还是没能安装好 aserve (当时貌似没有直接用 quicklisp 安装 aserve). 昨天忽然想到为什么不直接试试拿 quicklisp 安装 aserve, 也许其中需要修改的代码已经被修改过了(改天有时间了可以对照一下代码,看看修改了哪些地方), 今天试了一下,果然OK! 终于不用忍受ACL那个丑陋的界面, 可以直接在我的 Emacs 环境下调试 Web 程序了! :) CL-USER> (ql:quickload "aserve") To load "aserve": Install 5 Quicklisp releases: cl-ppcre ironclad nibbles portableaserve puri ; Fetching #<URL "http://beta.quicklisp.org/archive/puri/2010-10-06/puri-20101006-git.tgz"> ; 33.99KB ===========================

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

Call function in another lisp file

两盒软妹~` 提交于 2019-12-02 18:01:51
问题 I have to write a game in Lisp. In order to make it clear, I wanted to split the code in different .lisp files. How can I call a function out of a function in the other file? E.g. file1.lisp has a function called function1 and file2.lisp has a function called function2. How can I call function2 out of function1? Thanks! 回答1: Just so you know, there are a variety of different Lisp systems. I'll post the answer for Common Lisp. The naive way is to use (load "filename.lisp") , but that doesn't

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

newLISP你也行 --- 字符串

大兔子大兔子 提交于 2019-12-02 17:52:05
############################################################################# # Name: newLISP你也行 --- 流 # Author: 黄登 ( winger ) # Project: http://code.google.com/p/newlisp-you-can-do # Gtalk: free.winger@gmail.com # Gtalk-Group: zen0code@appspot.com # Blog: http://my.opera.com/freewinger/blog/ # QQ-Group: 31138659 # 大道至简 -- newLISP # # Copyright 2012 黄登 ( winger ) All rights reserved. # Permission is granted to copy, distribute and/or # modify this document under the terms of the GNU Free Documentation License, # Version 1.2 or any later version published by the Free Software Foundation ; #