lisp

padding binary-block lazy sequences

I have Clojure function that takes a sequence of numbers chops it into the appropriate number of bits and returns a lazy sequence of the chunks (lowest order bits first). It pads the high order bits of the last block to fill out the block size and I need advice on the "best way(tm)" to record the amount of padding while keeping it lazy a...

How is Lisp related to F#, and is learning Lisp a useful leg up to F#?

This is the situation : I mostly program C# and have written types in it I don't want to lose. At the same time I would like to learn functional programming. The obvious answer of course is F#. But for everything apart from C# I use emacs as an editor, and I really would like to learn Lisp too. (Learn your editors/IDE's language yo...

What is the time complexity of 'assoc' function in scheme?

What is the time complexity of this nifty function 'assoc'? ...

How to replace forwardslashes with backslashes in a string in lisp for emacs?

I would like to replace forward slaches to backslashes in emacs lisp. If I use this : (replace-regexp-in-string "\/" "\\" path)) I get an error. (error "Invalid use of `\\' in replacement text") So how to represent the backslash in the second regexp? ...

How do I write Push and Pop in Scheme?

Right now I have (define (push x a-list) (set! a-list (cons a-list x))) (define (pop a-list) (let ((result (first a-list))) (set! a-list (rest a-list)) result)) But I get this result: Welcome to DrScheme, version 4.2 [3m]. Language: Module; memory limit: 256 megabytes. > (define my-list (list 1 2 3)) > (push 4 my-list) ...

How do you compare two strings and ignore the case in Scheme?

I want to write a function like equalp, which gives #t for (equalp "Xy" "xY"). ...

Looking for (c)lisp examples of mini-languages, that is, DSLs.

Reading well-written code seems to help me learn a language. (At least it worked with C.) [deleting the 'over-specified' part of the question] I'm interested in particular in lisp's reputation as a language suited to creating a mini-language or DSL specific to a problem. The program ought to be open-source, of course, and available o...

How do I apply a symbol as a function in Scheme?

Hi, Is there a way I can apply '+ to '( 1 2 3)? edit: what i am trying to say is that the function i get will be a symbol. Is there a way to apply that? Thanks. ...

Position Independent Parameters to Scheme Functions

How do I pass position-independent parameters to scheme functions? ...

Unable to understand a line of Emacs Lisp

The line is function info() { emacs -eval "(progn (setq Man-notify-method 'bully) (info \"$1\"))" } I know from manuals that Progn progn is a special form in `C source code'. Setq setq is a special form in `C source code'. (setq SYM VAL SYM VAL ...) Set each SYM to the value of its VAL. The symbols SYM are...

Pattern Matching in Scheme

How do I accept the following input? (list of 0 or more charcters and ends with 3) or (list of 1 or more characters 4 and 0 or more characters after 4) something like (match ( list 3)) -> #t (match ( list 1 2 3)) -> #t (match (list 1 2 3 4)) -> #t (match (list 1 2 3 4 5)) -> #t (match (list 4)) -> #f EDIT: THIS IS NOT MY HO...

Clojure Variables and Looping

From googling around, I found that using while loops or using variables is discouraged. Now I implemented a very simple algorithm that will read characters from an inputstream and parse accordingly: if input is 10:abcdefghej it will parse out 10 then read next 10 bytes after the colon. The thing I am kinda lost with is how I can refact...

A good source for lisp libraries?

Is there a PEAR kind library for lisp? I hope there is, but I read somewhere that one of the disadvantages of lisp is its lack of serious libraries. I find that hard to believe since lisp is half a century old now. ...

Clojure loop reads one extra.

When length is 4 following loop executes 5 times. Reading 5 characters from the stream. (loop [i (.read stream) result "" counter length] (let [c (char i)] (println "=>" c) (if (zero? counter) result (recur (.read stream) (str result c) (dec counter))))) ...

What to learn? Lisp or OCaml or...?

I already have a few languages under my belt (in a rough order of expertise): Python, C, C++, PHP, Javascript, Haskell, Java, MIPS, x86 assembler. But it's been almost 2 years since I learned a new one, and I'm starting to get the itch. I have a few criteria: Must (repeat: must) have a free Linux implementation Should be different from...

adding metadata to a lazy sequence

When I try to add metadata to an infinite lazy sequence in Clojure, I get a stack overflow, and if I take off the metadata, then it works just fine. Why does adding the with-meta macro break the lazy seq? First create an infinite seq of a very nice number: (defn good [] (lazy-seq (cons 42 (good)))) user> (take 5 (good)) ...

C++ code and objects from C?

Is there a simple way to work with C++ objects directly from C? I want to expose some classes from C++ to C or to FFI(foreign function interface). Sure, I can write a stuff like that: class Foo{ .... }; void *make_foo(...){ Foo *ptr = new Foo(..) return static_cast<void *>(ptr); } .. int *foo_method1(void *fooptr, ...){ Foo *ptr = s...

Scheme Coding Style Questions

I am confused about the Scheme style for my code. Should I format if forms as: a. if() () () or b. if () () () or c. if () () () Should I format cond clauses as a. cond () () or b. cond () () When do I use a single ; to comment and a double ;;? ...

Why must 'require' be evaluated in a separate expression to use of the package

I have some lisp initialisation code: (eval-when (:compile-toplevel :load-toplevel :execute) (require 'asdf)) (eval-when (:compile-toplevel :load-toplevel :execute) (push #p"c\:\\lisp\\clsql-4.0.4\\" asdf:*central-registry*)) Why does that version compile, while this version: (eval-when (:compile-toplevel :load-toplevel :execute...

What is your recommended Emacs Lisp?

As for me, what I use is as follows recently yasnippets -- http://code.google.com/p/yasnippet/ If there is a good code, Could you introduce it for me? ...