Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 34

Thread: [Beginner] Programming Challenge: 6

  1. #11
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by Reiger View Post
    Yes, well that can be said for Haskell also.
    Not quite, but Haskell is a pure functional language (Lisp isn't), so I included it.

  2. #12
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by LaRoza View Post
    Code:
    if "Perl6" in ("Scheme", "Common Lisp", "Haskell"):
        print "Yes"
    else:
        print "Get some sleep and realise how silly that question is"


    Yes, it should be informative

    Eric Raymond in "How to Become a Hacker":
    pugs is a perl6 interpreter written in haskell, so technically, I would be writing haskell code.
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  3. #13
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: [Beginner] Programming Challenge: 6

    IIRC I did one of the challenges in Scheme...

  4. #14
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by slavik View Post
    pugs is a perl6 interpreter written in haskell, so technically, I would be writing haskell code.
    So writing Python code is writing C code? C is translated into GAS, but that doesn't count for writing assembly code. IronPython is written in C#, Jython in Java, therefore, writing Python is writing C#, C and Java at the same time.

    Maybe you need some sleep?

    Quote Originally Posted by nvteighen View Post
    IIRC I did one of the challenges in Scheme...
    You aren't a beginner, and anyone copying your submission will be forced to write Java code.

  5. #15
    Join Date
    Jul 2008
    Beans
    1,706

    Re: [Beginner] Programming Challenge: 6

    im am assuming i cannot use assembler like i asked and that it was a stupid question too

    but is OCaml valid?

  6. #16
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by jimi_hendrix View Post
    but is OCaml valid?
    If you give instructions on how to use it and it is available in the standard Ubuntu repos.

  7. #17
    Join Date
    Sep 2007
    Beans
    Hidden!

    Re: [Beginner] Programming Challenge: 6

    but is OCaml valid?
    It can be considered valid if you do not use an imperative style,and if you use tail recursion.

  8. #18
    Join Date
    Aug 2007
    Location
    Novocastria, Australia
    Beans
    751
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: [Beginner] Programming Challenge: 6

    I only started learning scheme about half an hour ago, but here is my attempt that I have come up with in that time. Constructive criticism is required, as I'm sure I have done a few silly things in there.

    Code:
    ;99 bottles of beer song in Scheme
    
    (begin
      (define beer
        (lambda (bottlesLeft)
          (if (>= bottlesLeft 1)
            (begin
              (display bottlesLeft)
              (display " bottle(s) of beer on the wall, ")
              (display bottlesLeft)
              (display " bottle(s) of beer, take one down, pass it around, ")
              (display (- bottlesLeft 1))
              (display " bottle(s) of beer on the wall.")
              (newline)
              (newline)
              (beer (- bottlesLeft 1)))
            (begin
              (display "Go to the store, buy some more, lots of ")
              (display "bottles of beer on the wall")))))
      (beer 100))

  9. #19
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by LaRoza View Post
    You aren't a beginner, and anyone copying your submission will be forced to write Java code.
    Hmm... I really would like to see it translated into Java... (http://ubuntuforums.org/showthread.p...98#post5688998)

  10. #20
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: [Beginner] Programming Challenge: 6

    Quote Originally Posted by NovaAesa View Post
    I only started learning scheme about half an hour ago, but here is my attempt that I have come up with in that time. Constructive criticism is required, as I'm sure I have done a few silly things in there.

    Code:
    ;99 bottles of beer song in Scheme
    
    (begin
      (define beer
        (lambda (bottlesLeft)
          (if (>= bottlesLeft 1)
            (begin
              (display bottlesLeft)
              (display " bottle(s) of beer on the wall, ")
              (display bottlesLeft)
              (display " bottle(s) of beer, take one down, pass it around, ")
              (display (- bottlesLeft 1))
              (display " bottle(s) of beer on the wall.")
              (newline)
              (newline)
              (beer (- bottlesLeft 1)))
            (begin
              (display "Go to the store, buy some more, lots of ")
              (display "bottles of beer on the wall")))))
      (beer 100))
    OK, let's see; it is good, but not too "Schemic".

    0. (define xx (lambda (yy) ...)) is usually shorthanded as (define (xx yy) (...)). Tutorials emphasize the first form to make you see that code = data, and that defining a function is just give a name to a lambda. But once you know that, you can use the syntactic sugar form, which is more widespread.

    1. In MIT/GNU Scheme, there's an procedure called (format) that allows you to print formatted output. Look at your implementation's documentation if there's something like that available for you.

    2. (begin) is evil. First, it breaks functional programming, as the return value of a (begin ...) is undefined; also, because usually it's a sign that your code should be broken into procedures. Of course, sometimes it simplifies stuff, but at the costs described above. Also, notice that the first (begin) is unnecessary: your interpreter will execute sequentially whatever you give to it... be it 100 procedures or a single one.

    3. Now, a philosophical observation. When developing in Lisp, you usually just define procedures that afterwards are executed by a user in the interpreter... in other words, in Lisp you program by creating a new language built "on Lisp" (in contrast to "built in Lisp") and therefore, it transforms itself into a new Lisp dialect specific to your task (Do you want to write a programming language? With Lisp, just do it!). And the Lisp interpreter you use will "automagically" be an interpreter for your language, and also the interface where the user, using your language, can perform some task (or write a script for it).

    Of course, as you've experienced, Lisp also allows you to write stuff in a "conventional way"... Notice that Lisp's power is not related with functional programming, but to the "code = data = code" principle.

    I *highly* recommend you to watch the MIT SICP videos at: http://groups.csail.mit.edu/mac/clas...sman-lectures/ And, of course, also look at the book (it's available free in the web). Even if the videos were recorded in 1986, they're pretty good to learn Scheme (and also some other CompSci cool stuff).
    Last edited by nvteighen; September 27th, 2008 at 01:36 PM.

Page 2 of 4 FirstFirst 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •