#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    DrRacket procedure


    I am working a bit with DrRacket and have a procedure I am having difficultly writing and executing. I want to take two ATOMS "X" and "N'. I want to add "X" to "X" for "N" number of times. i.e. for X is 2 and N is 5, I want 22222.
    Thanks in advance for any help or suggestions you have
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    (BTW--you may attract more attention by saying "Scheme" instead of "DrRacket". Most of us recognize former, but need to look up the latter.)

    It is helpful to see what progress you've made (and helps convince us you're not trying to get your homework done for you). Post code between [code]...[/code] tags to keep it legible. Also post any error messages you are getting (if any), what input you are supplying to the program, what you expect to happen and what happens instead. Additionally asking a specific question is more likely to get you help.

    This page (So, You Need to Write a Program but Don't Know How to Start) has some helpful pointers on how to start on a program. In your case, you find it helpful to think about the following: Given "X", can I write a function that returns "XX"? Given a number N, can I write a function that runs N times?
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Schemer/DrRacket


    Thanks OmegaZero. I did change the title in this reply as you suggested and below, to date, is my code.


    <code>

    (define duple
    (lambda (n x)
    (if (zero? n) '()
    (cons (x)
    (duple (- n 1) )))))

    (duple 2 5)

    </code>
  6. #4
  7. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Alpharetta, GA
    Posts
    1,806
    Rep Power
    1570
    I know this is a few days old, but I figured I might still be able to help, here.

    I see a few different problems with the code as written, mainly in that you seem to confuse the two arguments frequently. Perhaps some better names would help...

    The biggest problem you'll run into is how you are calling (cons); right now, you are trying to pass it a x in a list (it should be n here, but that's besides the point), but the effect of it is that the interpreter tries to execute a function called 'x', and complains when it can't find one. The correct call form would be

    Code:
    (define duple
       (lambda (original count)
          (if (zero? count) '()
             (cons original
                   (duple original (- count 1))))))
    Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
    #define KINSEY (rand() % 7) λ Scheme is the Red Pill
    Scheme in Short Understanding the C/C++ Preprocessor
    Taming Python A Highly Opinionated Review of Programming Languages for the Novice, v1.1

    FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0
    P.S. As more background, I want to be able to do this from the command
    line. So that's why I put the question that way. But also, I'm
    interested in trying to use Racket from Emacs. At the moment the only
    thing I really want now is "get the same thing as pressing F5 in
    DrRacket". And (again maybe I'm missing something obvious, or botched
    the config) neither Racket nor Geiser seem to provide just quite that.
    So I was looking at binding F5 to mode-compile and setting the correct
    Racket flags ... that I haven't figured out yet, because apparently
    I'm a numskull.

    Thank you.

IMN logo majestic logo threadwatch logo seochat tools logo