Search Results

Search found 9366 results on 375 pages for 'common lisp'.

Page 24/375 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • Scheme: what are the benefits of letrec?

    - by Ixmatus
    While reading "The Seasoned Schemer" I've begun to learn about letrec. I understand what it does (can be duplicated with a Y-Combinator) but the book is using it in lieu of recurring on the already defined function operating on arguments that remain static. An example of an old function using the defined function recurring on itself (nothing special): (define (substitute new old lat) (cond ((null? l) '()) ((eq? (car l) old) (cons new (substitute new old (cdr l)))) (else (cons (car l) (substitute new old (cdr l)))))) Now for an example of that same function but using letrec: (define (substitute new old lat) (letrec ((replace (lambda (l) (cond ((null? l) '()) ((eq? (car l) old) (cons new (replace (cdr l)))) (else (cons (car l) (replace (cdr l)))))))) (replace lat))) Aside from being slightly longer and more difficult to read I don't know why they are rewriting functions in the book to use letrec. Is there a speed enhancement when recurring over a static variable this way because you don't keep passing it?? Is this standard practice for functions with arguments that remain static but one argument that is reduced (such as recurring down the elements of a list)? Some input from more experienced Schemers/LISPers would help!

    Read the article

  • SOAP - Why do I need to query for the values for an update?

    - by Phill Pafford
    I'm taking over a project and wanted to understand if this is common practice using SOAP. The process that is currently in place I have to query all the values before I do an update cause I need to pass back all the values that are not being updated. Does this sound right? Example Values: fname=phill lname=pafford address=123 main phone:222-555-1212 So if I just wanted to update the phone number I need to query for the record, get all the values and submit these values for an update. Example Update Values: fname=phill lname=pafford address=123 main phone:111-555-1212 I just want to know if this is common practice or should I change the functionality of this?

    Read the article

  • Inheritance classes in Scheme

    - by DreamWalker
    Now I research OOP-part of Scheme. I can define class in Scheme like this: (define (create-queue) (let ((mpty #t) (the-list '())) (define (enque value) (set! the-list (append the-list (list value))) (set! mpty #f) the-list) (define (deque) (set! the-list (cdr the-list)) (if (= (length the-list) 0) (set! mpty #t)) the-list) (define (isEmpty) mpty) (define (ptl) the-list) (define (dispatch method) (cond ((eq? method 'enque) enque) ((eq? method 'deque) deque) ((eq? method 'isEmpty) isEmpty) ((eq? method 'print) ptl))) dispatch)) (Example from css.freetonik.com) Can I implement class inheritance in Scheme?

    Read the article

  • 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

  • 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

  • Haskell data serialization of some data implementing a common type class

    - by Evan
    Let's start with the following data A = A String deriving Show data B = B String deriving Show class X a where spooge :: a -> Q [ Some implementations of X for A and B ] Now let's say we have custom implementations of show and read, named show' and read' respectively which utilize Show as a serialization mechanism. I want show' and read' to have types show' :: X a => a -> String read' :: X a => String -> a So I can do things like f :: String -> [Q] f d = map (\x -> spooge $ read' x) d Where data could have been [show' (A "foo"), show' (B "bar")] In summary, I wanna serialize stuff of various types which share a common typeclass so I can call their separate implementations on the deserialized stuff automatically. Now, I realize you could write some template haskell which would generate a wrapper type, like data XWrap = AWrap A | BWrap B deriving (Show) and serialize the wrapped type which would guarantee that the type info would be stored with it, and that we'd be able to get ourselves back at least an XWrap... but is there a better way using haskell ninja-ery? EDIT Okay I need to be more application specific. This is an API. Users will define their As, and Bs and fs as they see fit. I don't ever want them hacking through the rest of the code updating their XWraps, or switches or anything. The most i'm willing to compromise is one list somewhere of all the A, B, etc. in some format. Why? Here's the application. A is "Download a file from an FTP server." B is "convert from flac to mp3". A contains username, password, port, etc. information. B contains file path information. A and B are Xs, and Xs shall be called "Tickets." Q is IO (). Spooge is runTicket. I want to read the tickets off into their relevant data types and then write generic code that will runTicket on the stuff read' from the stuff on disk. At some point I have to jam type information into the serialized data.

    Read the article

  • What common routines do you put in your Program.cs for C#

    - by Rick
    I'm interested in any common routine/procedures/methods that you might use in you Program.cs when creating a .NET project. For instance I commonly use the following code in my desktop applications to allow easy upgrades, single instance execution and friendly and simple reporting of uncaught system application errors. using System; using System.Diagnostics; using System.Threading; using System.Windows.Forms; namespace NameoftheAssembly { internal static class Program { /// <summary> /// The main entry point for the application. Modified to check for another running instance on the same computer and to catch and report any errors not explicitly checked for. /// </summary> [STAThread] private static void Main() { //for upgrading and installing newer versions string[] arguments = Environment.GetCommandLineArgs(); if (arguments.GetUpperBound(0) > 0) { foreach (string argument in arguments) { if (argument.Split('=')[0].ToLower().Equals("/u")) { string guid = argument.Split('=')[1]; string path = Environment.GetFolderPath(Environment.SpecialFolder.System); var si = new ProcessStartInfo(path + "\\msiexec.exe", "/x" + guid); Process.Start(si); Application.Exit(); } } //end of upgrade } else { bool onlyInstance = false; var mutex = new Mutex(true, Application.ProductName, out onlyInstance); if (!onlyInstance) { MessageBox.Show("Another copy of this running"); return; } AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.ThreadException += ApplicationThreadException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { try { var ex = (Exception) e.ExceptionObject; MessageBox.Show("Whoops! Please contact the developers with the following" + " information:\n\n" + ex.Message + ex.StackTrace, " Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } catch (Exception) { //do nothing - Another Exception! Wow not a good thing. } finally { Application.Exit(); } } public static void ApplicationThreadException(object sender, ThreadExceptionEventArgs e) { try { MessageBox.Show("Whoops! Please contact the developers with the following" + " information:\n\n" + e.Exception.Message + e.Exception.StackTrace, " Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); } catch (Exception) { //do nothing - Another Exception! Wow not a good thing. } } } } I find these routines to be very helpful. What methods have you found helpful in Program.cs?

    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

  • 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

  • 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

  • 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

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >