Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Imperative programming in scheme

Name: Anonymous 2012-01-14 3:03

So I know I can redefine variables with (set! var), but how would I do other imperative things, like for loops?

Name: Anonymous 2012-01-14 3:10

Tail recursion.

Name: Anonymous 2012-01-14 3:12

>>1
-> Tail recursion
-> (loop ...)
-> (dotimes (var number_of_times) ...)

Name: Anonymous 2012-01-14 3:15

>>1
set!
imperative things
Scheme

STOP.

Name: Anonymous 2012-01-14 3:33

>>3
(loop ...)

Thanks.
>>4
I'm trying to annoy the living fuck out of my professor. He was going off about how you can't redifine constants in Scheme, that technically there was one way to do it, but he wouldn't show us till the end of the quarter.... so I looked up how to do it. Now I just want to see how I could make the ugliest imperative beast of scheme possible.

In all fairness, I do value learning functional programming... even if I don't see myself using it much in the future.

Name: Anonymous 2012-01-14 3:40

>>5
It's all assembled to imperative. Tell him that and then claim that's why imperative is god mode.

Name: Anonymous 2012-01-14 3:51

>>6

The reason we have programming languages is to avoid assembly.

Name: Anonymous 2012-01-14 4:12

>>6
Not on a Lisp Machine, ``faggot''.

Name: Anonymous 2012-01-14 4:22

So anyways.... why was set! put into scheme if it was intended not to be used?

Name: Anonymous 2012-01-14 6:37

>>9

set! is, essentially, used by the evaluator during tail-call elimination to redefine a variable that identifies a constant, as constants are, pretty much, not mutable,  and is provided in the language to make code easier to read. So, your professor is entirely correct in saying it's not possible to redefine constants in scheme and you are blithely ignorant for thinking you know more about the language than her/him.

Name: Anonymous 2012-01-14 13:35

(define-syntax while
  (syntax-rules ()
    ((while (break-name continue-name) cond body ...)
     (call-with-current-continuation
      (lambda (break-name)
        (let loop ()
          (call-with-current-continuation
           (lambda (continue-name)
             body ...))
          (if cond (loop))))))))

(define-syntax for
  (syntax-rules ()
    ((for (break-name continue-name) (init cond incr) body ...)
     (begin init
            (while (break-name continue-name) cond body ... incr)))))

Name: Anonymous 2012-01-15 5:38

ITT: faggots and their professors can't even be bothered to RTFM

http://docs.racket-lang.org/guide/for.html


(for ([i '(1 2 3)])
    (display i))

Don't change these.
Name: Email:
Entire Thread Thread List