Search Results

Search found 1630 results on 66 pages for 'plt scheme'.

Page 1/66 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • About "If.." in Scheme (plt-scheme)

    - by Amit
    I had a pretty simple requirement in my Scheme program to execute more than one statement, in the true condition of a 'if'. . So I write my code, something like this: (if (= 1 1) ((expression1) (expression2)) ; these 2 expressions are to be executed when the condition is true (expression3) ) Obviously, the above doesn't work, since I have unintentionally created a # procedure with # arguments. So, to get my work done, I simply put the above expressions in a new function and call it from there, in place of the expression1, expression2. It works. So, my point here is: is there any other conditional construct which may support my requirement here?

    Read the article

  • scheme vs common lisp: war stories

    - by SuperElectric
    There are no shortage of vague "Scheme vs Common Lisp" questions on StackOverflow, so I want to make this one more focused. The question is for people who have coded in both languages: While coding in Scheme, what specific elements of your Common Lisp coding experience did you miss most? Or, inversely, while coding in Common Lisp, what did you miss from coding in Scheme? I don't necessarily mean just language features. The following are all valid things to miss, as far as the question is concerned: Specific libraries. Specific features of development environments like SLIME, DrRacket, etc. Features of particular implementations, like Gambit's ability to write blocks of C code directly into your Scheme source. And of course, language features. Examples of the sort of answers I'm hoping for: "I was trying to implement X in Common Lisp, and if I had Scheme's first-class continuations, I totally would've just done Y, but instead I had to do Z, which was more of a pain." "Scripting the build process in Scheme project, got increasingly painful as my source tree grew and I linked in more and more C libraries. For my next project, I moved back to Common Lisp." "I have a large existing C++ codebase, and for me, being able to embed C++ calls directly in my Gambit Scheme code was totally worth any shortcomings that Scheme may have vs Common Lisp, even including lack of SWIG support." So, I'm hoping for war stories, rather than general sentiments like "Scheme is a simpler language" etc.

    Read the article

  • Scheme vs Common Lisp: war stories

    - by SuperElectric
    There are no shortage of vague "Scheme vs Common Lisp" questions on both StackOverflow and on this site, so I want to make this one more focused. The question is for people who have coded in both languages: While coding in Scheme, what specific elements of your Common Lisp coding experience did you miss most? Or, inversely, while coding in Common Lisp, what did you miss from coding in Scheme? I don't necessarily mean just language features. The following are all valid things to miss, as far as the question is concerned: Specific libraries. Specific features of development environments like SLIME, DrRacket, etc. Features of particular implementations, like Gambit's ability to write blocks of C code directly into your Scheme source. And of course, language features. Examples of the sort of answers I'm hoping for: "I was trying to implement X in Common Lisp, and if I had Scheme's first-class continuations, I totally would've just done Y, but instead I had to do Z, which was more of a pain." "Scripting the build process in my Scheme project got increasingly painful as my source tree grew and I linked in more and more C libraries. For my next project, I moved back to Common Lisp." "I have a large existing C++ codebase, and for me, being able to embed C++ calls directly in my Gambit Scheme code was totally worth any shortcomings that Scheme may have vs Common Lisp, even including lack of SWIG support." So, I'm hoping for war stories, rather than general sentiments like "Scheme is a simpler language" etc.

    Read the article

  • PLT Scheme Memory

    - by Eric
    So I need some help with implementing a Make-memory program using Scheme. I need two messages 'write and 'read. So it would be like (mymem 'write 34 -116) and (mymem 'read 99) right? and (define mymem (make-memory 100)).....How would I implement this in scheme? using an Alist???I need some help coding it. I have this code which makes make-memory a procedure and when you run mymem you get ((99.0)) and what i need to do is recur this so i get an alist with dotted pairs to ((0.0)). So any suggestions on how to code this?? Does anyone have any ideas what I could do to recur and make messages Write and read?? (define make-memory (lambda (n) (letrec ((mem '()) (dump (display mem))) (lambda () (if (= n 0) (cons (cons n 0) mem) mem) (cons (cons (- n 1) 0) mem)) (lambda (msg loc val) (cond ((equal? msg 'read) (display (cons n val))(set! n (- n 1))) ((equal? msg 'write) (set! mem (cons val loc)) (set! n (- n 1)) (display mem))))))) (define mymem (make-memory 100)) Yes this is an assignment but I wrote this code. I just need some help or direction. And yes I do know about variable-length argument lists.

    Read the article

  • PLT Scheme URL dispatch

    - by Inaimathi
    I'm trying to hook up URL dispatch with PLT Scheme. I've taken a look at the tutorial and the server documentation. I can figure out how to route requests to the same servlets. Specific example: (define (start request) (blog-dispatch request)) (define-values (blog-dispatch blog-url) (dispatch-rules (("") list-posts) (("posts" (string-arg)) review-post) (("archive" (integer-arg) (integer-arg)) review-archive) (else list-posts))) (define (list-posts req) `(list-posts)) (define (review-post req p) `(review-post ,p)) (define (review-archive req y m) `(review-archive ,y ,m)) Assuming the above code running on a server listening 8080, localhost:8080/ goes to a page that says "list-posts". Going to localhost:8080/posts/test goes to a PLT "file not found" page (with the above code, I'd expect it to go to a page that says "review-post test"). It feels like I'm missing something small and obvious. Can anyone give me a hint?

    Read the article

  • What Scheme Does Ghuloum Use?

    - by Don Wakefield
    I'm trying to work my way through Compilers: Backend to Frontend (and Back to Front Again) by Abdulaziz Ghuloum. It seems abbreviated from what one would expect in a full course/seminar, so I'm trying to fill in the pieces myself. For instance, I have tried to use his testing framework in the R5RS flavor of DrScheme, but it doesn't seem to like the macro stuff: src/ghuloum/tests/tests-driver.scm:6:4: read: illegal use of open square bracket I've read his intro paper on the course, An Incremental Approach to Compiler Construction, which gives a great overview of the techniques used, and mentions a couple of Schemes with features one might want to implement for 'extra credit', but he doesn't mention the Scheme he uses in the course. Update I'm still digging into the original question (investigating options such as Petit Scheme suggested by Eli below), but found an interesting link relating to Gholoum's work, so I am including it here. [Ikarus Scheme](http://en.wikipedia.org/wiki/Ikarus_(Scheme_implementation)) is the actual implementation of Ghuloum's ideas, and appears to have been part of his Ph.D. work. It's supposed to be one of the first implementations of R6RS. I'm trying to install Ikarus now, but the configure script doesn't want to recognize my system's install of libgmp.so, so my problems are still unresolved. Example The following example seems to work in PLT 2.4.2 running in DrEd using the Pretty Big (require lang/plt-pretty-big) (load "/Users/donaldwakefield/ghuloum/tests/tests-driver.scm") (load "/Users/donaldwakefield/ghuloum/tests/tests-1.1-req.scm") (define (emit-program x) (unless (integer? x) (error "---")) (emit " .text") (emit " .globl scheme_entry") (emit " .type scheme_entry, @function") (emit "scheme_entry:") (emit " movl $~s, %eax" x) (emit " ret") ) Attempting to replace the require directive with #lang scheme results in the error message foo.scm:7:3: expand: unbound identifier in module in: emit which appears to be due to a failure to load tests-driver.scm. Attempting to use #lang r6rs disables the REPL, which I'd really like to use, so I'm going to try to continue with Pretty Big. My thanks to Eli Barzilay for his patient help.

    Read the article

  • Multidimensional vectors in scheme?

    - by incrediman
    I earlier asked a question about arrays in scheme (turns out they're called vectors but are basically otherwise the same as you'd expect). Is there an easy way to do multidimensional arrays vectors in PLT Scheme though? For my purposes I'd like to have a procedure called make-multid-vector or something. By the way if this doesn't already exist, I don't need a full code example of how to implement it. If I have to roll this myself I'd appreciate some general direction though. The way I'd probably do it is to just iterate through each element of the currently highest dimension of the vector to add another dimension, but I can see that being a bit ugly using scheme's recursive setup. Also, this seems like something I should have been able to find myself so please know that I did actually google it and nothing came up.

    Read the article

  • Write Scheme data structures so they can be eval-d back in, or alternative

    - by Jesse Millikan
    I'm writing an application (A juggling pattern animator) in PLT Scheme that accepts Scheme expressions as values for some fields. I'm attempting to write a small text editor that will let me "explode" expressions into expressions that can still be eval'd but contain the data as literals for manual tweaking. For example, (4hss->sexp "747") is a function call that generates a legitimate pattern. If I eval and print that, it becomes (((7 3) - - -) (- - (4 2) -) (- (7 2) - -) (- - - (7 1)) ((4 0) - - -) (- - (7 0) -) (- (7 2) - -) (- - - (4 3)) ((7 3) - - -) (- - (7 0) -) (- (4 1) - -) (- - - (7 1))) which can be "read" as a string, but will not "eval" the same as the function. For this statement, of course, what I need would be as simple as (quote (((7 3... but other examples are non-trivial. This one, for example, contains structs which print as vectors: pair-of-jugglers ; --> (#(struct:hand #(struct:position -0.35 2.0 1.0) #(struct:position -0.6 2.05 1.1) 1.832595714594046) #(struct:hand #(struct:position 0.35 2.0 1.0) #(struct:position 0.6 2.0500000000000003 1.1) 1.308996938995747) #(struct:hand #(struct:position 0.35 -2.0 1.0) #(struct:position 0.6 -2.05 1.1) -1.3089969389957472) #(struct:hand #(struct:position -0.35 -2.0 1.0) #(struct:position -0.6 -2.05 1.1) -1.8325957145940461)) I've thought of at least three possible solutions, none of which I like very much. Solution A is to write a recursive eval-able output function myself for a reasonably large subset of the values that I might be using. There (probably...) won't be any circular references by the nature of the data structures used, so that wouldn't be such a long job. The output would end up looking like `(((3 0) (... ; ex 1 `(,(make-hand (make-position ... ; ex 2 Or even worse if I could't figure out how to do it properly with quasiquoting. Solution B would be to write out everything as (read (open-input-string "(big-long-s-expression)")) which, technically, solves the problem I'm bringing up but is... ugly. Solution C might be a different approach of giving up eval and using only read for parsing input, or an uglier approach where the s-expression is used as directly data if eval fails, but those both seem unpleasant compared to using scheme values directly. Undiscovered Solution D would be a PLT Scheme option, function or library I haven't located that would match Solution A. Help me out before I start having bad recursion dreams again.

    Read the article

  • Fetch elements from List in scheme

    - by fireball003
    Hi, How to go through a list or fetch element from a list in scheme? How can I name each element (like we do for variables in java) in a list? Thanks in advance. I want to compare every point in a list to another point. So, as we do in java or python- for(int i;i<list.size();i++){ if (list[i]> k){ //do something } } How can I do similar thing in scheme?

    Read the article

  • Practical Scheme Programming

    - by Ixmatus
    It's been a few months since I've touched Scheme and decided to implement a command line income partitioner using Scheme. My initial implementation used plain recursion over the continuation, but I figured a continuation would be more appropriate to this type of program. I would appreciate it if anyone (more skilled with Scheme than I) could take a look at this and suggest improvements. I'm that the multiple (display... lines is an ideal opportunity to use a macro as well (I just haven't gotten to macros yet). (define (ab-income) (call/cc (lambda (cc) (let ((out (display "Income: ")) (income (string->number (read-line)))) (cond ((<= income 600) (display (format "Please enter an amount greater than $600.00~n~n")) (cc (ab-income))) (else (let ((bills (* (/ 30 100) income)) (taxes (* (/ 20 100) income)) (savings (* (/ 10 100) income)) (checking (* (/ 40 100) income))) (display (format "~nDeduct for bills:---------------------- $~a~n" (real->decimal-string bills 2))) (display (format "Deduct for taxes:---------------------- $~a~n" (real->decimal-string taxes 2))) (display (format "Deduct for savings:-------------------- $~a~n" (real->decimal-string savings 2))) (display (format "Remainder for checking:---------------- $~a~n" (real->decimal-string checking 2)))))))))) Invoking (ab-income) asks for input and if anything below 600 is provided it (from my understanding) returns (ab-income) at the current-continuation. My first implementation (as I said earlier) used plain-jane recursion. It wasn't bad at all either but I figured every return call to (ab-income) if the value was below 600 kept expanding the function. (please correct me if that apprehension is incorrect!)

    Read the article

  • How do I make a module in PLT Scheme?

    - by kunjaan
    I tried doing this: #lang scheme (module duck scheme/base (provide num-eggs quack) (define num-eggs 2) (define (quack n) (unless (zero? n) (printf "quack\n") (quack (sub1 n))))) But I get this error: module: illegal use (not at top-level) in: (module duck scheme/base (provide num-eggs quack) (define num-eggs 2) (define (quack n) (unless (zero? n) (printf "quack\n") (quack (sub1 n))))) what is the correct way?

    Read the article

  • Scheme Beginner question

    - by Robert
    Hello.I am trying to put the following statement in Dr.Scheme: {with {x {+ 5 5}} {+ x x}} but I got an error: expand: unbound identifier in module in: with anyone could help me?Thanks.

    Read the article

  • How to bind "rest" variables to list of values in macro in Scheme

    - by Slartibartfast
    I want to make a helper macro for writing match-extensions. I have something like this: (define-match-expander my-expander (? (stx) (let* ([dat (cdr (syntax-e stx))] [var1 (car dat))] [var2 (cadr dat)]) ;transformer goes here ))) So I wanted a macro that will do this let binding. I've started with something like this: (define-syntax-rule (define-my-expander (id vars ...) body) (define-match-expander id (? (stx) (match-let ([(vars ...) (cdr (syntax-e stx))]) body)))) but match-let isn't defined in transformation time. First question would be is there any other way of doing this (making this expanders, I mean)? Maybe there is already something similar in plt-scheme that I'm not aware of, or I'm doing it wrong in some way. Regardless of answer on the first question, if I ever want to bound list of variables to list of values inside of a macro, how should I do it? EDIT: In combination with Eli's answer macro now looks like this: (define-syntax-rule (define-my-expander (id vars ...) body) (define-match-expander id (? (stx) (syntax-case stx () [(_ vars ...) body]))))

    Read the article

  • Scheme Depth-first search of a graph function

    - by John Retallack
    This is a homework question,I'm trying to do a Depth-first search function in Scheme,Here's the code I've written so far: (define explore (?(node visited) (let* ([neighbors (force (cdr node))] [next (nextNode visited neighbors)] [is-visited (member? node visited)]) (cond ;if I have no unvisited neighbours print current node and go up one level [(equal? next #f) (begin (display (car node)) (display " "))] ;if current node is not visited and I have unvisited neighbors ;print current node,mark as visited and visit it's neighbors [(and (equal? is-visited #f) (not (equal? next #f))) (begin (display (car node)) (display " ") (explore next (cons node visited)))]) ;go and visit the next neighbor (if (not (equal? (nextNode (cons next visited) neighbors) #f )) (explore (nextNode (cons next visited) neighbors) (cons node visited)))))) 'node' is the current node 'visited' is a list in witch I keep track of the nodes I visited 'nextNode' is a function that returns the first unvisited neighbor if any or #f otherwise 'member?' test's if a node is in the visited list The Graph representation is using adjacent made using references to nodes with letrec so that's why I use force in 'neighbors': Eg: (letrec ([node1 (list "NY" (delay (list node2 node3)))],where node2 and node3 are defined as node1 The problem witch I'm dealing with is that my visited lists looses track of some of the nodes I visited when I come out of recursion,How can I fix this ?

    Read the article

  • Methods and properties in scheme - is object oriented programming possible in scheme?

    - by incrediman
    I will use a simple example to illustrate my question. In Java, C, or any other OOP language, I could create a pie class in a way similar to this: class Apple{ public String flavor; public int pieces; private int tastiness; public goodness(){ return tastiness*pieces; } } What's the best way to do that with Scheme? I suppose I could do with something like this: (define make-pie (lambda (flavor pieces tastiness) (list flavor pieces tastiness))) (define pie-goodness (lambda (pie) (* (list-ref pie 1) (list-ref pie 2)))) (pie-goodness (make-pie 'cherry 2 5)) ;output: 10 ...where cherry is the flavor, 2 is the pieces, and 5 is the tastiness. However then there's no type-safety or visibility, and everything's just shoved in an unlabeled list. How can I improve that? Sidenote: The make-pie procedure expects 3 arguments. If I want to make some of them optional (like I'd be able to in curly-brace languages like Java or C), is it good practice to just take the arguments in as a list (that is treat the arguments as a list - not require one argument which is a list) and deal with them that way?

    Read the article

  • Approaching SICP in Clojure instead of Scheme

    - by ironicaldiction
    I am a third year bachelor student in a software engineering program, and I brought up the idea of reading SICP to an adviser to gain a deeper and more fundamental understanding of the principles behind all this software we engineer. He suggested not to learn Scheme to complete the book (because it's not as common as modern dialects of Lisp) but to do the exercises in Clojure instead. It's an already difficult book, if I do attempt the book's exercises in the more modern Clojure, how would that work? For example, I can't find any real solutions, the syntax they teach for Scheme is different, etc.

    Read the article

  • What should I learn from Scheme?

    - by bunglestink
    I was wondering what unique features I can learn from Scheme that would help me become a better programmer? I have a lot experience in mainstream languages, and I am looking to expand my horizons and learn about functional aspects that are missing from other languages. I am familiar with closures from javascript, lambda expressions from C#, and I was wondering what I can focus on that is lacking in other languages? Aside from the Lisp syntax, I feel like what I have seen so far I've already encountered in other languages. What is unique to Scheme/Lisp that will teach me something new?

    Read the article

  • Am I getting Scheme wrong?

    - by nischayn22
    Inspired by the numerous posts about the importance of learning Lisp/Scheme I started to learn Scheme two days back, I am using the book "The little Schemer" and have completed half of it. But I still haven't learned anything new, the book teaches about recursion which I already understand and uses lambda (which I can think of a way to define a function in C). I still haven't got the concept of functional programming (please point to some example of functional compared to normal programming methods in C/C++ so I can get it). Am I learning in the wrong way? or is "The little Schemer" for a newbie in programming and I should look for some other books?

    Read the article

  • Scheme Formatting Help

    - by Logan
    I've been working on a project for school that takes functions from a class file and turns them into object/classes. The assignment is all about object oriented programming in scheme. My problem however is that my code doesn't format right. The output it gives me whenever I give it a file to pass in wraps the methods of the class in a list, making it so that the class never really gets declared. I can't for the life of me figure out how to get the parenthesis wrapping the method list to remove. I would really appreciate any help. Below is the code and the class file. ;;;; PART1 --- A super-easy set of classes. Just models points and lines. Tests all of the ;; basics of class behavior without touching on anything particularly complex. (class pointInstance (parent:) (constructor_args:) (ivars: (myx 1) (myy 2)) (methods: (getx () myx) (gety () myy) (setx (x) (set! myx x)) (show () (begin (display "[") (display myx) (display ",") (display myy) (display "]"))) )) (require (lib "trace.ss")) ;; Continue reading until you hit the end of the file, all the while ;; building a list with the contents (define load-file (lambda (port) (let ((rec (read port))) (if (eof-object? rec) '() (cons rec (load-file port)))))) ;; Open a port based on a file name using open-input-file (define (load fname) (let ((fport (open-input-file fname))) (load-file fport))) ;(define lis (load "C:\\Users\\Logan\\Desktop\\simpletest.txt")) ;(define lis (load "C:\\Users\\Logan\\Desktop\\complextest.txt")) (define lis (load "C:\\Users\\Logan\\Desktop\\pointinstance.txt")) ;(display (cdaddr (cdddar lis))) (define makeMethodList (lambda (listToMake retList) ;(display listToMake) (cond [(null? listToMake) retList ;(display "The list passed in to parse was null") ] [else (makeMethodList (cdr listToMake) (append retList (list (getMethodLine listToMake)))) ] ) )) ;(trace makeMethodList) ;this works provided you just pass in the function line (define getMethodLine (lambda (functionList) `((eq? (car msg) ,(caar functionList)) ,(caddar functionList)))) (define load-classes (lambda paramList (cond [(null? paramList) (display "Your parameters are null, man.")] [(null? (car paramList))(display "Done creating class definitions.")] [(not (null? (car paramList))) (begin (let* ((className (cadaar paramList)) (classInstanceVars (cdaddr (cddaar paramList))) (classMethodList (cdr (cadddr (cddaar paramList)))) (desiredMethodList (makeMethodList classMethodList '())) ) ;(display "Classname: ") ;(display className) ;(newline)(newline) ;(display "Class Instance Vars: ") ;(display classInstanceVars) ;(newline)(newline) ;(display "Class Method List: ") ;(display classMethodList) ;(newline) ;(display "Desired Method List: ") ;(display desiredMethodList)) ;(newline)(newline) ;---------------------------------------------------- ;do not delete the below code!` `(define ,className (let ,classInstanceVars (lambda msg ;return the function list here (cond ,(makeMethodList classMethodList '()))) )) ;--------------------------------------------------- ))] ) )) (load-classes lis) ;(load-classes lis) ;(load-classes-helper lis) ;(load-classes "simpletest.txt") ;(load-classes "complextest.txt") ;method list ;(display (cdr (cadddr (cddaar <class>))))

    Read the article

  • Detecting EOF in a Binary File using Scheme

    - by yuguang
    (define (read-all-input) (local ((define line (bytes->list (read-bytes 4)))) (if (eof-object? line) empty (cons line (read-all-input))))) (void (read-all-input)) The above code fails because bytes-list expects an argument of type byte string, but is given #

    Read the article

  • Binary Trees in Scheme

    - by Javier
    Consider the following BNF defining trees of numbers. Notice that a tree can either be a leaf, a node-1 with one subtrees, or a node-2 with two subtrees. tree ::= (’leaf number) | (’node-1 tree) | (’node-2 tree tree) a. Write a template for recursive procedures on these trees. b. Define the procedure (leaf-count t) that returns the number of leaves in t > (leaf-count ’(leaf 5)) 1 > (leaf-count ’(node-2 (leaf 25) (leaf 17))) 2 > (leaf-count ’(node-1 (node-2 (leaf 4) (node-2 (leaf 2) (leaf 3))))) 3 Here's what I have so far: ;define what a leaf, node-1, and node-2 is (define leaf list) (define node-1 list) (define node-2 list) ;procedure to decide if a list is a leaf or a node (define (leaf? tree) (number? (car tree))) (define (node? tree) (pair? (car tree))) (define (leaf-count tree) (cond ((null? tree) 0) ((number? tree) 0) ((leaf? tree) 1) (else (+ (leaf-count (car tree)) (leaf-count (cdr tree)))))) It looks like it should run just fine, but when I try to run it using a simple test case like (leaf-count '(leaf 5)) I get the following error message: car: expects argument of type pair; given leaf What does this error message mean? I am defining a leaf as a list. But for some reason, it's not seeing that and gives me that error message.

    Read the article

  • Matrix addition in Scheme

    - by user285012
    I am trying to add a matrix and it is not working... (define (matrix-matrix-add a b) (map (lambda (row) (row-matrix-add row b)) a)) (define (row-matrix-add row matrix) (if (null? (car matrix)) '() (cons (add-m row (map car matrix)) (row-matrix-add row (map cdr matrix))))) (define (add-m row col) (if (null? col) 0 (+ (car row) (car col) (add-m (cdr row) (cdr col)))))

    Read the article

  • Scheme - Memory System

    - by Eric
    I am trying to make a memory system where you input something in a slot of memory. So what I am doing is making an Alist and the car of the pairs is the memory location and the cdr is the val. I need the program to understand two messages, Read and Write. Read just displaying the memory location selected and the val that is assigned to that location and write changes the val of the location or address. How do I make my code so it reads the location you want it to and write to the location you want it to? Feel free to test this yourself. Any help would be much appreciated. This is what I have: (define make-memory (lambda (n) (letrec ((mem '()) (dump (display mem))) (lambda () (if (= n 0) (cons (cons n 0) mem) mem) (cons (cons (- n 1) 0) mem)) (lambda (msg loc val) (cond ((equal? msg 'read) (display (cons n val))(set! n (- n 1))) ((equal? msg 'write) (set! mem (cons val loc)) (set! n (- n 1)) (display mem))))))) (define mymem (make-memory 100))

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >