Search Results

Search found 488 results on 20 pages for 'lisp'.

Page 11/20 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Force CL-Lex to read whole word

    - by Flávio Cruz
    I'm using CL-Lex to implement a lexer (as input for CL-YACC) and my language has several keywords such as "let" and "in". However, while the lexer recognizes such keywords, it does too much. When it finds words such as "init", it returns the first token as IN, while it should return a "CONST" token for the "init" word. This is a simple version of the lexer: (define-string-lexer lexer (...) ("in" (return (values :in $@))) ("[a-z]([a-z]|[A-Z]|\_)" (return (values :const $@)))) How do I force the lexer to fully read the whole word until some whitespace appears?

    Read the article

  • Find all paths from root to leaves of tree in Scheme

    - by grifaton
    Given a tree, I want to find the paths from the root to each leaf. So, for this tree: D / B / \ A E \ C-F-G has the following paths from root (A) to leaves (D, E, G): (A B D), (A B E), (A C F G) If I represent the tree above as (A (B D E) (C (F G))) then the function g does the trick: (define (g tree) (cond ((empty? tree) '()) ((pair? tree) (map (lambda (path) (if (pair? path) (cons (car tree) path) (cons (car tree) (list path)))) (map2 g (cdr tree)))) (else (list tree)))) (define (map2 fn lst) (if (empty? lst) '() (append (fn (car lst)) (map2 fn (cdr lst))))) But this looks all wrong. I've not had to do this kind of thinking for a while, but I feel there should be a neater way of doing it. Any ideas for a better solution (in any language) would be appreciated.

    Read the article

  • [emacs] make ibuffer-visit-buffer behave like ido-switch-to-buffer?

    - by Stephen
    Is there a way to make ibuffer-visit-buffer behave like ido-switch-to-buffer (with raise-frame option)? If there is a window/frame containing the buffer I'd like emacs to take me there rather than opening the same buffer in the current window. I guess switch-to-buffer is remapped to ido-switch-to-buffer when ido-mode is turned on, so would doing something like that work in this case (remap ibuffer-visit-buffer to ido-switch-to-buffer)? Thanks

    Read the article

  • Does CLOS have an eql specialization dispatch on strings?

    - by mhb
    Examples of what you can do. (defmethod some-fn ((num real)) (print "an integer")) (defmethod some-fn ((num real)) (print "a real")) (defmethod some-fn ((num (eql 0))) (print "zero")) (some-fn 19323923198319) "an integer" (some-fn 19323923198319.3) "a real" (some-fn 0) "zero" It also works with a general 'string type. (defmethod some-fn ((num string)) (print "a string")) (some-fn "asrt") "a string" Not with a specific string, however (defmethod some-fn ((num (eql "A")) (print "a specifict string"))) => doesn't compile I imagine it doesn't work because eql does not work on strings in the way that would be necessary for it to work. (eql "a" "a") => nil Is there a way to do it?

    Read the article

  • Emacs: adding 1 to every number made of 2 digits inside a marked region

    - by WizardOfOdds
    Imagine I've got the following in a text file opened under Emacs: some 34 word 30 another 38 thing 59 to 39 say 10 here 47 and I want to turn into this, adding 1 to every number made of 2 digits: some 35 word 31 another 39 thing 60 to 40 say 11 here 48 (this is a short example, my actual need is on a much bigger list, not my call) How can I do this from Emacs? I don't mind calling some external Perl/sed/whatever magic as long as the call is made directly from Emacs and operates only on the marked region I want. How would you automate this from Emacs? I think the answer I'm thinking of consist in calling shell-command-on-region and replace the region by the output... But I'm not sure as to how to concretely do this.

    Read the article

  • emacs list-buffers behavior

    - by Stephen
    In GNU emacs, every time I hit Ctrl-x Ctrl-b to see all of my buffers, the window is split to show the buffer list, or if I have my window already split in 2 (for instance, I will have a shell running in the lower window), the buffer list appears in the other window. My desired behavior is for the buffer list to appear in my active window so that I can select the buffer I want and continue to working in the same window, rather than having to Ctrl-x Ctrl-o to the other buffer, selecting the buffer (with enter) and editing that buffer in the other window... I've googled for it but it doesn't seem to be a common desire? I wonder if anyone has an elispy (or other) solution?

    Read the article

  • How do I configure emacs for editing HTML files that contain Javascript?

    - by MakeDummy
    I have started the painful first steps of using emacs to edit an HTML file with both HTML tags and javascript content. I have installed nxhtml and tried using it - i.e set up to use nxhtml-mumamo-mode for .html files. But I am not loving it. When I am editing the Javascript portion of the code the tab indents do not behave as they do when editing C/C++ code. It starts putting tabs within the line and if you try and hit tab in the white space preceding a line it inserts the tab rather than re-tabifying the line. Another aspect that I don't like is that it doesn't do syntax colouring like the usual C/C++ modes do. I much prefer the behaviour of the default java-mode when editing HTML files but that doesn't play nicely with the HTML code. :-( 1) Is there a better mode for editing HTML files with Javascript portions? 2) Is there a way to get nxhtml to use the default java-mode for the javascript portions? Regards, M

    Read the article

  • How do I write Push and Pop in Scheme?

    - by kunjaan
    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) > my-list (1 2 3) > (pop my-list) 1 > my-list (1 2 3) What am I doing wrong? Is there a better way to write push so that the element is added at the end and pop so that the element gets deleted from the first?

    Read the article

  • How to change aif to be able to access 'it' within the macrocall without making 'it' public in the package

    - by Sim
    If you put the aif code presented in onlisp in a package and try to use it in another you run in the problem that packagename:it is not external. (in-package :packagename) (defmacro aif (test-form then-form &optional else-form) ‘(let ((it ,test-form)) (if it ,then-form ,else-form))) wanted call syntax (in-package :otherpackage) (aif (do-stuff) (FORMAT t "~a~%" it) (FORMAT t "just got nil~%")) How can I fix this behavior in code, without making the variable it external in the package declaration and beeing able to access it just by it instead of packagename:it?

    Read the article

  • Writing an Eval Procedure in Scheme?

    - by Planeman
    My problem isn't with the built-in eval procedure but how to create a simplistic version of it. Just for starters I would like to be able to take this in '(+ 1 2) and have it evaluate the expression + where the quote usually takes off the evaluation. I have been thinking about this and found a couple things that might be useful: Unquote: , (quasiquote) (apply) My main problem is regaining the value of + as a procedure and not a symbol. Once I get that I think I should just be able to use it with the other contents of the list. Any tips or guidance would be much appreciated.

    Read the article

  • Finding greatest product of two lists, but keep getting #unspecific

    - by user1787030
    (define (greatest-product lst1 lst2) (define (helper lst addtimes total toacc) (cond ((null? lst) '()) ((= (countatoms lst) 1) (display total)) ((= addtimes (cadr lst)) (helper (cdr lst) 1 total total)) (else (helper lst (+ 1 addtimes) (+ toacc total) toacc)))) (cond ((> (helper lst1 0 0 (car lst1)) (helper lst2 0 0 (car lst2))) (helper lst1 0 0 (car lst1))) ((< (helper lst1 0 0 (car lst1)) (helper lst2 0 0 (car lst2))) (helper lst2 0 0 (car lst2))) ((= (helper lst1 0 0 (car lst1)) (helper lst2 0 0 (car lst2))) (display 'equal)))) Scheme keeps returning back that it cannot perform the procedure with #unspecific Im running it with (display (greatest-product '(1 2 3) '(4 5 6))) (display (greatest-product '(1 2 3) '(1 2 3))) (display (greatest-product '(1 2 3) '())) what is wrong with it? the problem seems to be occurring

    Read the article

  • How to cast a character to int in Clojure?

    - by Learning Clojure
    How to cast a character to int in Clojure? I am trying to write a rot 13 in clojure, so I need to have something to cast my char to int. I found something called (int), so I put: (int a) Get: CompilerException java.lang.RuntimeException: Unable to resolve symbol: a in this context, compiling:(NO_SOURCE_PATH:13:1) Then I put: (int 'a) Get: ClassCastException clojure.lang.Symbol cannot be cast to java.lang.Character clojure.lang.RT.intCast (RT.java:1087) Then: (rot13 ''a') Get: ClassCastException clojure.lang.PersistentList cannot be cast to java.lang.Character clojure.lang.RT.intCast (RT.java:1087) And: (rot13 "a") Get: ClassCastException java.lang.String cannot be cast to java.lang.Character clojure.lang.RT.intCast (RT.java:1087) So what is the right way to do it? btw, I always get confused with all these clojure syntax. But I can never find any source only help me with my problem. Any suggestions? Thank you!!

    Read the article

  • Scheme Function to reverse elements of list of 2-list

    - by sudhirc
    This is an exercise from EOPL. Procedure (invert lst) takes lst which is a list of 2-lists and returns a list with each 2-list reversed. (define invert (lambda (lst) (cond((null? lst ) '()) ((= 2 (rtn-len (car lst))) ( cons(swap-elem (car lst)) (invert (cdr lst)))) ("List is not a 2-List")))) ;; Auxiliry Procedure swap-elements of 2 element list (define swap-elem (lambda (lst) (cons (car (cdr lst)) (car lst)))) ;; returns lengh of the list by calling (define rtn-len (lambda (lst) (calc-len lst 0))) ;; calculate length of the list (define calc-len (lambda (lst n) (if (null? lst) n (calc-len (cdr lst) (+ n 1))))) This seems to work however looks very verbose. Can this be shortened or written in more elegant way ? How I can halt the processing in any of the individual element is not a 2-list? At the moment execution proceed to next member and replacing current member with "List is not a 2-List" if current member is not a 2-list.

    Read the article

  • format - Help with printing a table

    - by Michael Kohl
    This question will probably end in a facepalm, but I've tried for a while and am still stuck despite reading through the hyperspec. Basically what I want to do is something like (format t "~{|~{ ~5d~}|~%~}" '((1 23 2 312) (23 456 1 7890))) but instead of hard-coding the 5 it should be calculated from the list (length of longest element from any nested list + 1) to give something like | 1 23 2 312| | 23 456 1 7890| Maybe I'm thinking way too complicated here and there is an easier way to do what I want, but I think I ran myself into a mental corner that I can't get out of.

    Read the article

  • Why does using cons to create a pair of two lists produce a list and two elements?

    - by fingerprint211b
    I've started learning Scheme, for fun mostly, and because I've never used a functional language before. I chose Scheme because I wanted to read SICP for a long time. Anyway, I'm currently learning about lists, and before that I learned about cons, car and cdr. And there's an example that creates a list of lists with cons, like this : (cons (list 1 2) (list 3 4)) The resulting list is ((1 2) 3 4), which doesn't make sense to me, I would expect ((1 2)(3 4)) to be the result (a list made out of two lists). Why does it behave like that? I realize that if I were to use car, I would get (1 2), and cdr I'd get (3 4) becaue cdr always returns "the rest", but I don't understand why the list isn't made of two lists?

    Read the article

  • Generate Permutations of a List

    - by Eric Mercer
    I'm writing a function that takes a list and returns a list of permutations of the argument. I know how to do it by using a function that removes an element and then recursively use that function to generate all permutations. I now have a problem where I want to use the following function: (define (insert-everywhere item lst) (define (helper item L1 L2) (if (null? L2) (cons (append L1 (cons item '())) '()) (cons (append L1 (cons item L2)) (helper item (append L1 (cons (car L2) '())) (cdr L2))))) (helper item '() lst)) This function will insert the item into every possible location of the list, like the following: (insert-everywhere 1 '(a b)) will get: '((1 a b) (a 1 b) (a b 1)) How would I use this function to get all permutations of a list? I now have: (define (permutations lst) (if (null? lst) '() (insert-helper (car lst) (permutations (cdr lst))))) (define (insert-helper item lst) (cond ((null? lst) '()) (else (append (insert-everywhere item (car lst)) (insert-helper item (cdr lst)))))) but doing (permutations '(1 2 3)) just returns the empty list '().

    Read the article

  • Consecutive calls/evaulations in a form?

    - by Dave
    Hey guys, simple question... Working with XLISP to write a program, but I've seemed to run into a simple fundamental problem that I can't seem to work around: perhaps someone has a quick fix. I'm trying to write an if statement who's then-clause evaluates multiple forms and returns the value of the last. In example: (setq POSITION 'DINING-ROOM) (defun LOOK (DIRECTION ROOM) ... ) (defun SETPOS (ROOM) ... ) (defun WHERE () ... ) (defun MOVE (DIRECTION) (if (not(equal nil (LOOK DIRECTION POSITION))) ; If there is a room in that direction ( ; Then-block: Go to that room. Return where you are. (SETPOS (LOOK DIRECTION ROOM)) (WHERE) ) ( ; Else-block: Return error (list 'CANT 'GO 'THERE) ) ) The logical equivalent intended is: function Move (Direction) { if(Look(Direction, Room) != null) { SetPos(Look(Direction,Room)); return Where(); } else { return "Can't go there"; } } (Apologies for the poor web-formatting.) The problem I have is with: ( (SETPOS (LOOK DIRECTION ROOM)) (WHERE) ) I simply want to return the evaluation of WHERE, but I need to execute the SETPOS function first. XLISP doesn't like the extra parentheses: if I remove the outer set, my WHERE list becomes my else (I don't want that). If I remove the sets around SETPOS and WHERE, it treats WHERE like an argument for SETPOS; I also don't want that. So, how do I simply evaluate the first, then the second and then return the values of the last evaluated?

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >