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

Pages: 1-4041-8081-

A student's question

Name: Anonymous 2011-05-30 12:20

My teacher keeps drilling into our collective heads that using the break command is harmful, and that if we wish to terminate a loop early it would be far better to create a boolean variable, set it to 0, and add a condition to the head of the loop, and set the boolean variable to 1 when a break is needed. Note that this way you actually have to check this every single loop (where it is not needed almost every time) as well as waste a command to reset the boolean in case it was set to true.

Is there a reason to this?

Name: Anonymous 2011-05-30 12:27

dont question u tutor u piece of shit

Name: Anonymous 2011-05-30 12:28

That's stupid. Use break.

Name: Anonymous 2011-05-30 12:31

our collective heads
So the set of student-tasks is multiplexed onto a smaller set of kernel-schedulable heads, or what?

Name: Anonymous 2011-05-30 12:36

>>3
Thought so, but wanted to make sure I wasn't missing some deep magic. Thank you.
>>4
I have to admit, I lol'd

Name: Anonymous 2011-05-30 12:44

It's about source code clarity. Ensuring loops and functions have only one entry point and only one exit point keeps control flow simple and lessens the risk of introducing bugs when modifying the code.

It's the kind of rule that you're likely to see in large projects where it's expected someone else will have to do maintenance on your code years after you've left the company.

Name: Anonymous 2011-05-30 13:16

Hilarious, it must suck being taught by such a fucking idiot. At least they're not a women.

Name: Anonymous 2011-05-30 13:18

>>7
Weird, I assumed they were a women when I first read >>1.

Name: Anonymous 2011-05-30 13:20

...She is a woman, yes.

Name: Anonymous 2011-05-30 13:21

>>1
Your teacher is a idiot. Let's say I have a Devyrish piece of code that determines if a number is prime..

boolean isPrime = true;

for (int divisor = 2; divisor <= number/2 && isPrime; divisor++) {
  if (number % divisor == 0) {
    isPrime = false:
  }
}

Now let's say I wanna be like the SICP fags that roam this joint and abstract this loop. What do I abstract? Divisor or isPrime?

The answer becomes a bit clearer if I would re-write this loop using a break statement.

Name: Anonymous 2011-05-30 13:23

>>9
oh well that explains it...

just ignore them then. If they try to get on at you for not doing what they say slap her and tell her to "know her fucking place". Works a charm.

Name: Anonymous 2011-05-30 13:28

>>10
You could abstract the second clause in the for(;;) to be divisor <= number/divisor

Name: Anonymous 2011-05-30 13:35

Use goto.

Name: Anonymous 2011-05-30 13:35

>>12
And let's say that I wanted do what is sometimes called "method abstraction".

Using boolean values, it would be hard to tell if the method should be called divisor() or isPrime(). Whereas if I re-wrote this looping using a break statement, I could pretty much tell right away that the method would be called isPrime().

Name: Anonymous 2011-05-30 14:59

>>13
His teacher would probably get an aneurysm.

Name: Anonymous 2011-05-30 16:21

>>1
Yes. Break is harmful. You should read SICP and use continuations instead of loops with break/continue.

Name: Anonymous 2011-05-30 16:35

>>16
No. SICP is harmful. You should use break and continue instead of Lisp faggotry.

Name: Anonymous 2011-05-30 16:42

>>17
Young man, you have learned a little bit and think you knows it all, but soon you will grow out of your sophomoric sophistication and come to realize that the world is more complicated, and you will begin again to understand that LISP is The Right Thing.

Name: Anonymous 2011-05-30 16:45

>>18
What can LISP offer over C?

Name: Anonymous 2011-05-30 16:48

>>18
no, lisp is for faggots

Name: Anonymous 2011-05-30 16:49

>>19
macros.

Name: Anonymous 2011-05-30 16:50

>>19
functionality

Name: Anonymous 2011-05-30 17:00

>>21
Consider me an ignorant barbarian for a moment (because I largely am when it comes to LISP), and explain to me the virtues and advantages of macros.

Name: Anonymous 2011-05-30 17:15

>>16-23
But Scheme has break and continue! They are called call-with-current-continuation!
This should be portable R6RS code, but it is untested
(define-syntax while
  (lambda (stx)
    (syntax-case stx ()
      ((while cond body body+ ...)
       (with-syntax ((break (datum->syntax #'body 'break))
                     (continue (datum->syntax #'body 'continue)))
         #'(let loop ()
             (call-with-current-continuation
              (lambda (break)
                (let loop ()
                  (when cond
                    (call-with-current-continuation
                     (lambda (continue)
                       body body+ ...))
                    (loop)))))))))))

(define-syntax for
  (lambda (stx)
    (syntax-case stx ()
      ((for init cond incr body body+ ...)
       (with-syntax ((break (datum->syntax #'body 'break))
                     (continue (datum->syntax #'body 'continue)))
         #'(call-with-current-continuation
            (lambda (break)
              init
              (let loop ()
                (when cond
                  (call-with-current-continuation
                   (lambda (continue)
                     body body+ ...))
                  incr (loop))))))))))

;(while #t (display "read ") (display "SICP "))
; => read SICP read SICP read SICP
;(while #t (display "read ") (continue) (display "SICP"))
; => read read read read ...
;(while #t (display "read ") (break) (display "SICP"))
; => read


Yes, continue does the right thing in for (executes incr).
If you had read your SICP today, you would've known. You also would known that all the call-with-current-continuations can be optimized to call-with-escape-continuations.

Name: Anonymous 2011-05-30 17:19

>>1
this:

for(int ii=0; ii<1000; ii++) {
    for(int jj=0; jj<1000; jj++) {
        for(int kk=0; kk<1000; kk++) {
            if(wantToBreak) goto loopEnd;
        }
    }
}
loopEnd:
...

is by some considered bad. However i prefer this solution over:

needToBreak = false
for(int ii=0; ii<1000 && !needToBreak; ii++) {
    for(int jj=0; jj<1000 && !needToBreak; jj++) {
        for(int kk=0; kk<1000 && !needToBreak; kk++) {
            if(wantToBreak) needToBreak = true;
        }
    }
}

and definitely instead of

needToBreak = false
for(int ii=0; ii<1000 && !needToBreak; ii++) {
    for(int jj=0; jj<1000 && !needToBreak; jj++) {
        for(int kk=0; kk<1000 && !needToBreak; kk++) {
            if(wantToBreak) {
                needToBreak = true;
                break
            }
        }
        if(needToBreak) break;
    }
    if(needToBreak) break;
}


bottom line: break is fine as long as you want to break from non-nested loop

Name: Anonymous 2011-05-30 17:23

>>25
The last one is 50% redundant. How about:
il: for(int ii=0; ii<1000; ii++) {
    jl: for(int jj=0; jj<1000; jj++) {
        kl: for(int kk=0; kk<1000; kk++) {
            if (wantToBreak) break il;
        }
    }
}

Name: Anonymous 2011-05-30 17:25

You should just use perl and next labels.

Name: Anonymous 2011-05-30 17:29

>>24
Optimized Racket version:

(define-syntax-parameter break
  (lambda (stx)
    (raise-syntax-error 'break "not in a loop")))
(define-syntax-parameter continue
  (lambda (stx)
    (raise-syntax-error 'continue "not in a loop")))

(define-syntax-rule (let-stxparam ((x y) ...) . body)
  (syntax-parameterize ((x (syntax-rules () ((x) (y)))) ...)
    . body))
(define-syntax-rule (let/ec-stxparam x . body)
  (let/ec k
    (let-stxparam ((x k)) . body)))

(define-syntax-rule (for init cond incr . body)
  (let/ec-stxparam break
    init
    (let loop ()
      (when cond
        (let/ec-stxparam continue . body)
        incr (loop)))))
(define-syntax-rule (while cond . body)
  (for (void) cond (void) . body))

Name: Anonymous 2011-05-30 17:30

>>26
we're speaking about c, c++ or java?

Name: Anonymous 2011-05-30 17:33

>>29
aight, no bool / boolean in c so that leaves c++/java.
but c++ does not support break with labels so java

Name: Anonymous 2011-05-30 17:35

>>26
They are all call-with-escape-continuation. That may be implemented with CL's block+return-from too (same concept).

(define-syntax for/break-at
  (syntax-rules ()
    ((_ name init cond body . rest)
     (call-with-current-continuation
      (lambda (name) (for init cond body . rest))))))
;; short one
(define-syntax-rule (for/break-at n . rest)
  (let/ec n (for . rest)))

(for/break-at il (set! ii 0) (< ii 1000) (inc! ii)
 (for/break-at jl (set! jj 0) (< jj 1000) (inc! jj)
  (for/break-at kl (set! kk 0) (< kk 1000) (inc! kk)
   (when break? (il)))))


It looks bad, though, but that's because I'm just forcing C-style for into Scheme.

Name: Anonymous 2011-05-30 17:42

>>31
Also, an implementation of CL's tagbody (not exactly, same semantics, different syntax) in Racket, but it should be easily portable to R6RS too:

(define-syntax-parameter goto
  (lambda (stx)
    (raise-syntax-error 'goto (if (identifier? stx) "bad syntax" "bad syntax (not inside a tagbody)") stx)))

(define-syntax (tagbody stx)
  (define (%tag-next x)
    (let ((x (syntax->list x)))
      (do ((x x (cdr x))
           (y (cdr x) (cdr y))
           (r (list (car x)) (cons (list (car x) (car y)) r)))
        ((null? y) (reverse (cons (list (car x) #'void) r))))))
  (syntax-case stx ()
    ((tagbody (tag b ...) ...)
     (andmap identifier? (syntax->list #'(tag ...)))
     (with-syntax (((first (tag next) ...) (%tag-next #'(tag ...))))
       #'(letrec ((tag
                   (lambda ()
                     (let/ec escape
                       (syntax-parameterize
                           ((goto (lambda (stx)
                                    (syntax-case stx ()
                                      ((goto label)
                                       (if (and (identifier? #'label)
                                                (or (free-identifier=? #'label #'tag) ...))
                                           #'(escape label)
                                           (raise-syntax-error 'goto "bad syntax (not a valid label)" stx #'label)))))))
                         b ...
                         (next))))) ...)
           (let loop ((f (first)))
             (if (procedure? f) (loop (f)) f)))))))


;; Example taken from the HyperSpec: http://www.lispworks.com/documentation/HyperSpec/Body/s_tagbod.htm
(define-syntax-rule (inc! x n) (set! x (+ x n)))

(let ((val #f))
  (tagbody
   (start
    (set! val 1)
    (goto point-a)
    (inc! val 16))
   (point-c
    (inc! val 4)
    (goto point-b)
    (inc! val 32))
   (point-a
    (inc! val 2)
    (goto point-c)
    (inc! val 64))
   (point-b
    (inc! val 8)))
  val)
; 15


Really, more languages should provide some non-local exit mechanism, and not in the form of exceptions.

Name: Anonymous 2011-05-30 18:04

>>23
Macro systems have a range of uses. Being able to choose the order of evaluation (see lazy evaluation and non-strict functions) enables the creation of new syntactic constructs (e.g. control structures) indistinguishable from those built into the language. For instance, in a Lisp dialect that has cond but lacks if, it is possible to define the latter in terms of the former using macros.

Next, macros make it possible to define data languages that are immediately compiled into code, which means that constructs such as state machines can be implemented in a way that is both natural and efficient.[8]

Macros can also be used to introduce new binding constructs. The most well-known example is the transformation of let into the application of a function to a set of arguments.

Felleisen conjectures[9] that these three categories make up the primary legitimate uses of macros in such a system.

Name: Anonymous 2011-05-30 18:07

>>33
where are the footnotes, faggot?

Name: Anonymous 2011-05-30 18:18

>>25
That's pretty much the situation. Could you explain why the first is considered bad by some? Is it more or less what >>6 said, or is there a more mechanical reason?

Name: Anonymous 2011-05-30 18:21

>>32
And try-catch-finally-style exceptions:
And this, >>23, is why macros and continuations are important: I, alone, in less than one hour, have written what takes ages in other languages.

(define exception-handler
  (make-parameter (lambda (x) (error "uncaught exception:" x))))

(define (throw x)
  ((exception-handler) x))

(define-syntax try
  (syntax-rules (catch else finally)
    ((try body ... (catch exception (predicate . pbody) ...) (finally . fbody))
     (let* ((finally (lambda () . fbody))
            (old-throw (exception-handler))
            (handler (lambda (exception)
                       (let ((x (cond ((predicate exception) . pbody) ...
                                      (else (finally) (old-throw exception)))))
                         (finally) x))))
       (let/ec throw-cont
         (let ((x (parameterize ((exception-handler (lambda (x) (throw-cont (handler x)))))
                    body ...)))
           (finally) x))))
    ((try body ... (catch exception (predicate . pbody) ...))
     (try body ... (catch exception (predicate . pbody) ...) (finally (void))))
    ((try body ... (finally . fbody))
     (try body ... (catch e) (finally . fbody)))))

(try
 (try
  2
  (throw 3)
  4
  (catch e
    (string? (display "not here")))
  (finally (display "finally")))
 4
 (catch e
   (number? (display " here") e)))

; output: finally here
; returns: 3

Name: Anonymous 2011-05-30 18:57

>>30
For every numeric type, C has 0 is false and everything else is true.
>>31
This is cool beans. I wish I knew more lisps ;_;

Name: Anonymous 2011-05-30 19:02

>>36
That code sucks in terms of trying to get your point across.

Name: Anonymous 2011-05-30 19:04

>>24
You get a F for the lame attempt at an explanation. Ever hear of being concise and to the point you retard? Given that long and verbose shit code, I bet not.

Name: Anonymous 2011-05-30 19:07

>>38
It sucks pretty hard actually, I know that, but I wanted to avoid set!/boxes/mutation.

>>37
Only Java has labeled breaks, though. C# has goto.

Name: Anonymous 2011-05-30 19:12

>>39
You don't understand, that is(should be) PORTABLE (R6RS) Scheme code. It may be the first and last time you'll ever see such kind of Scheme code for the rest of your life. See >>28 for the unportable, fast, do-what-I-mean, properly (un)hygienic version.

Name: Anonymous 2011-05-30 19:17

>>41
It's incoherent gibberish. Again, you get the big fat F for trying to be clear and concise.

Name: Anonymous 2011-05-30 19:25

>>42
I can't read it and feel offended by someone that knows something that I don't know and don't like.
Well, it's not my fault if you didn't read your SICP.

Name: Anonymous 2011-05-30 19:34

>>43
Why? So I can end up like a shigt manager at taco bell like you?

Name: Anonymous 2011-05-30 19:41

>>44
We don't even have taco bell here, we're not inferior murricans, we don't need cheap fast ````food'''' (now with 80% of real meat less) to live. Enjoy living in a decading shitty country that thinks it's the center of the universe while the world moves on. Also, enjoy being an ignorant cretin basement dweller that will never even be employed at your precious taco bell and will die alone with no family and offspring.

Name: Anonymous 2011-05-30 19:43

>>44
Also go back to /g/, we don't like having fucking retarded idiots that just hate something with no fucking logical reason besides not understanding/not liking it.

Name: Anonymous 2011-05-30 19:45

>>45
I work as a Java Programmer for Kodak Gallery here in Emeryville, California.

Name: Anonymous 2011-05-30 19:54

>>36
Common Lisp: defmacro
---------------
Scheme/Racket: begin-for-syntax syntax-e syntax->datum syntax->list syntax-property #' (void) quote-syntax datum->syntax syntax-parameter-value syntax-rule raise-syntax-error internal-definition-context? syntax-parameterize make-set!-transformer prop:set!-transformer free-identifier=? syntax-local-value/immediate syntax-local-transforming-module-provides? syntax-local-module-defined-identifiers syntax-local-module-required-identifiers make-require-transformer (require (lib "stxparam.ss" "mzlib")) syntax? (require mzlib/defmacro) define-macro syntax-local-lift-expression (require racket/stxparam-exptime) make-rename-transformer syntax-local-require-certifier make-parameter-rename-transformer syntax-local-value define-syntax-parameter make-provide-transformer syntax-local-provide-certifier syntax-source local-expand/capture-lifts local-transformer-expand/capture-lifts syntax-local-lift-values-expression syntax-local-lift-module-end-declaration syntax-local-lift-require syntax-local-lift-provide syntax-local-name syntax-local-context syntax-local-phase-level syntax-local-module-exports syntax-local-get-shadower syntax-local-certifier syntax-transforming? syntax-local-introduce make-syntax-introducer exn:fail:syntax make-syntax-delta-introducer syntax-local-make-delta-introducer syntax-case define-syntax syntax-rules with-syntax syntax-position syntax-line syntax-column ...

Name: Anonymous 2011-05-30 19:59

>>46
The crap wasn't clear and concise. On top of that, the original code wasn't even in a Lisp dialect. WTF? Do you have ADD in real life?

Name: Anonymous 2011-05-30 20:17

>>47
Good for you, code monkey. Back to typing now. Make sure to catch all your exceptions.

>>49
You lack either reading comprehension or sense of humor.

>>48
I don't have time to play with you today. I'll just say that only syntax-e, datum->syntax, quote-syntax and define-syntax are required. In CL, quote, defmacro, define-symbol-macro and gensym are required. 4 definitions, 4 definitions. Go away.

Name: Anonymous 2011-05-30 20:18

>>49
Also, define what is clear and concise.

Name: Anonymous 2011-05-30 20:28

What the fuck is going on in this thread.

Name: Anonymous 2011-05-30 20:33

>>50
fuck you lithp faggot

Name: Anonymous 2011-05-30 20:35

>>50
only syntax-e, datum->syntax, quote-syntax and define-syntax are required.
But you can't read Scheme code without knowing the rest!

Name: Anonymous 2011-05-30 20:36

>>50
Go complete your shift at taco bell SICP bitch.

Name: Anonymous 2011-05-30 20:36

>>54
You also need to go complete your shift at taco bell SICP bitch.

Name: Anonymous 2011-05-30 20:37

Homework: define defmacro using syntax-case.

Name: List UPDATED 2011-05-30 20:38

>>57
Scheme/Racket: defmacro begin-for-syntax syntax-e syntax->datum syntax->list syntax-property #' (void) quote-syntax datum->syntax syntax-parameter-value syntax-rule raise-syntax-error internal-definition-context? syntax-parameterize make-set!-transformer prop:set!-transformer free-identifier=? syntax-local-value/immediate syntax-local-transforming-module-provides? syntax-local-module-defined-identifiers syntax-local-module-required-identifiers make-require-transformer (require (lib "stxparam.ss" "mzlib")) syntax? (require mzlib/defmacro) define-macro syntax-local-lift-expression (require racket/stxparam-exptime) make-rename-transformer syntax-local-require-certifier make-parameter-rename-transformer syntax-local-value define-syntax-parameter make-provide-transformer syntax-local-provide-certifier syntax-source local-expand/capture-lifts local-transformer-expand/capture-lifts syntax-local-lift-values-expression syntax-local-lift-module-end-declaration syntax-local-lift-require syntax-local-lift-provide syntax-local-name syntax-local-context syntax-local-phase-level syntax-local-module-exports syntax-local-get-shadower syntax-local-certifier syntax-transforming? syntax-local-introduce make-syntax-introducer exn:fail:syntax make-syntax-delta-introducer syntax-local-make-delta-introducer syntax-case define-syntax syntax-rules with-syntax syntax-position syntax-line syntax-column ...

Name: Anonymous 2011-05-30 20:40

>>57
Important: Although define-macro is non-hygienic, it is still restricted by Racket’s phase separation rules. This means that a macro cannot access run-time bindings, because it is executed in the syntax-expansion phase. Translating code that involves define-macro or defmacro from an implementation without this restriction usually implies separating macro related functionality into a begin-for-syntax or a module (that will be imported with require-for-syntax) and properly distinguishing syntactic information from run-time information.

Name: Anonymous 2011-05-30 20:44

>>57
5 lines of code, no need to use syntax-case:

(define-syntax-rule (define-macro (name . args) . body)
  (define-syntax (name stx)
    (if (symbol? (syntax-e stx))
        (error 'name "can't be used as symbol")
        (datum->syntax stx (apply (lambda args . body) (cdr (syntax->datum stx)))))))
;; syntax->datum recursively applies syntax-e

(define-macro (aif cond true false)
  `(let ((it ,cond))
     (if it ,true ,false)))

(aif 2 it #f)


Homework: define syntax-case using defmacro in less than 5 lines.

Name: Anonymous 2011-05-30 20:45

>>59
Why would you need to access runtime values at compile-time?

Name: Anonymous 2011-05-30 20:47

>>61
I've a `custom-defun` macro and I want to save argument info for runtime.

Name: Anonymous 2011-05-30 20:47

>>61
WHY DO I WEAR MY SISTER'S BLACK LEGGINGS?

IT'S BECAUSE I GET A MASSIVE BONER FROM IT.

Name: Anonymous 2011-05-30 20:50

The main problem with Racket's macro system (and with other syntax-case systems) is that instead of raw s-expressions you're dealing with syntax objects. This becomes very ugly when identifiers are handled: instead of dealing with plain symbols, you're dealing with these syntax values (called “identifiers” in this case) that are essentially a symbol and some opaque information that represents the lexical scope for its source. In several syntax-case systems this is the only difference from defmacro macros, but in the Racket case this applies to everything — identifiers, numbers, other immediate constants, and even function applications, etc — they are all wrapped.

Name: Anonymous 2011-05-30 20:51

>>62
You need the info at runtime, you just generate it at compile-time.

Name: Anonymous 2011-05-30 20:51

>>65
But I want to pass it inner macros!!!

Name: Anonymous 2011-05-30 20:52

>>64
How is this bad and look up ER macros/syntactic closures.

Name: Anonymous 2011-05-30 20:52

>>65
you just generate it at compile-time.
To do this I need access to a hash-table, shared between all macros!

Name: Anonymous 2011-05-30 20:53

>>66
I don't think I understood, you want the information both for compile-time inner macros inside the custom-defun and runtime? Provide it for both.

Name: Anonymous 2011-05-30 20:55

>>69
restricted by Racket’s phase separation rules. This means that a macro cannot access run-time bindings

Name: Anonymous 2011-05-30 20:55

The op never mentioned a fucking thing about a lisp dialect. The fact that you retards have managed to convert it to one makes you a morons. Now I see why you all work shit hourly jobs.

Name: Anonymous 2011-05-30 20:56

>>1
I occasionally come across code written in this style. It's harder to read since you don't get the "get out of the loop NOW" effect of a break statement, and what would otherwise be code that simply follows the break now turns into the body of another conditional. Trying to replace multiple breaks in a loop with booleans gets even more hairy. The efficiency implications are similarly obvious.

The only situation in which it could be considered more readable would be to a (very dumb) decompiler.

Name: Anonymous 2011-05-30 20:56

>>68
So what?
(begin-for-syntax
  (define my-hash (make-hash)))

(define-syntax (set-hash stx)
  (let ((x (syntax->datum stx)))
    (hash-set! my-hash (cadr x) (caddr x))
    (quote-syntax (void))))

(define-syntax (get-hash stx)
  (let ((x (syntax->datum stx)))
    (datum->syntax stx (hash-ref my-hash (cadr x)))))

(set-hash x 2)
(get-hash x) ; 2

Name: Anonymous 2011-05-30 20:59

>>70
And so? Let macro live in the domain of macros. Nothing of value was lost.

>>71
This thread peacefully ended when we discovered that >>1's teacher was female. Now it's just free trolling, like the one you're doing right now.

Name: Anonymous 2011-05-30 21:05

It's a fucking stupid idea.  Consider:


for(int i = 0; i < 100; i++)
{
   beat();
   if(hadEnough()) break;
   punch();
   if(hadEnough()) break;
   kick();
   if(hadEnough()) break;
}



Now you have to re-write it:


bool hadEnoughVar = false;
for(int i = 0; (i < 100) && !hadEnoughVar; i++)
{
   beat();
   if(hadEnough())
   {
      hadEnoughVar = true;
   }
   else
   {
      punch();
      if(hadEnough())
      {
         hadEnoughVar = true;
      }
      else
      {
         kick();
         if(hadEnough()) hadEnoughVar = true;
      }
   }
}

Name: Anonymous 2011-05-30 21:11

>>69
for compile-time inner macros inside the custom-defun and runtime?
Can you do following in Scheme/Racket?

(defparameter *current-function* nil)

(defmacro custom-defun (name args &rest body &environment env)
  (let ((*current-function* name))
    `(defun ,name ,args
       ,@(mapcar (lambda (x) (sb-cltl2:macroexpand-all x env)) body))))

(defmacro this-function ()
  `',*current-function*)

Name: Anonymous 2011-05-30 21:12

>>76
Now,

(custom-defun yoba () (this-function))
(yoba)

would print it's name.

Name: Anonymous 2011-05-30 21:14

>>77
it's
Also,
(define this-function
  (make-parameter #f))

(define-syntax-rule (defun f args . body)
  (define (f . args)
    (parameterize ((this-function 'f))
      . body)))

(defun f () (this-function))
(f)

Name: Anonymous 2011-05-30 21:15

>>73
>(begin-for-syntax ...
But earlier you have said that only syntax-e, datum->syntax, quote-syntax and define-syntax are required!!!

Name: Anonymous 2011-05-30 21:16

>>78
So, where are curstom-defun and *current-function* global variable?

Name: Anonymous 2011-05-30 21:17

>>78
Sorry, I misread,
(define current-function
  (make-parameter #f))

(define-syntax-rule (this-function)
  (object-name (current-function)))

(define-syntax-rule (defun f args . body)
  (define (f . args)
    (parameterize ((current-function f))
      . body)))

(defun f () (this-function))
(f)

Name: Anonymous 2011-05-30 21:17

>>78

$ mzscheme
Welcome to MzScheme v372 [3m], Copyright (c) 2004-2007 PLT Scheme Inc.
    (define this-function
      (make-parameter #f))

    (define-syntax-rule (defun f args . body)
      (define (f . args)
        (parameterize ((this-function 'f))
          . body)))

    (defun f () (this-function))
    (f)

stdin::78: application: bad syntax in: (defun f args . body)
reference to undefined identifier: defun
reference to undefined identifier: f

Name: Anonymous 2011-05-30 21:18

>>79
You can probably have a phaseless syntax-case system.

Name: Anonymous 2011-05-30 21:18

>>81

$ mzscheme
Welcome to MzScheme v372 [3m], Copyright (c) 2004-2007 PLT Scheme Inc.
Sorry, I misread,
(define current-function
  (make-parameter #f))

(define-syntax-rule (this-function)
  (object-name (current-function)))

(define-syntax-rule (defun f args . body)
  (define (f . args)
    (parameterize ((current-function f))
      . body)))

(defun f () (this-function))
(f)reference to undefined identifier: Sorry
stdin::5: unquote: not in quasiquote in: (unquote I)
reference to undefined identifier: misread
stdin::16: unquote: not in quasiquote in: (unquote (define current-function (make-parameter #f)))
reference to undefined identifier: define-syntax-rule
stdin::160: application: bad syntax in: (defun f args . body)
reference to undefined identifier: defun

Name: Anonymous 2011-05-30 21:19

>>82
v372
Are you stuck in 2007 or something?

Name: Anonymous 2011-05-30 21:20

Welcome to Racket v5.1.1.5.
#;> (define current-function
      (make-parameter #f))
#;>
    (define-syntax-rule (this-function)
      (object-name (current-function)))
#;>
    (define-syntax-rule (defun f args . body)
      (define (f . args)
        (parameterize ((current-function f))
          . body)))
#;>
    (defun f () (this-function))
#;> (f)
'f
#;>

Name: Anonymous 2011-05-30 21:20

>>85
Have you heard about backward-compatibility?

Name: Anonymous 2011-05-30 21:21

>>86
You mean this shit isn't standard?

Name: Anonymous 2011-05-30 21:22

>>86

$ mzscheme
Welcome to MzScheme v372 [3m], Copyright (c) 2004-2007 PLT Scheme Inc.
(define current-function
      (make-parameter #f))
(define-syntax-rule (this-function)
      (object-name (current-function)))
reference to undefined identifier: define-syntax-rule

Name: Anonymous 2011-05-30 21:22

>>87
Yes, MzScheme is still supported for backward-compatibility (just like r5rs, just like r6rs, just like #lang scheme), but Racket is not MzScheme.

Name: Anonymous 2011-05-30 21:25

>>88
syntax-case is r6rs standard, (define-syntax (head . args) . body) is a widespread extension to define-syntax, (define-syntax-rule (f . pat) . body) is sugar for (define-syntax f (syntax-rules () (pat . body))), make-parameter and parameterize are R6RS, R7RS and SRFI-I-don't-remember, object-name is non-standard.

Name: Anonymous 2011-05-30 21:29

>>91
That is why I love CL. It's so much simplier!

Name: Anonymous 2011-05-30 21:34

>>92
CLISP has its own non-standard extensions, SBCL has its own non-standard extensions, ClozureCL has its own non-standard extensions. Racket is a language derived from Scheme, use a r5rs-by-default implementation like Chicken.

Name: Anonymous 2011-05-30 21:35

>>93
LispWorks has its own non-standard extensions, CMUCL has them too, and that's why Hemlock is (was?) CMUCL-only.

Name: Anonymous 2011-05-30 21:38

>>92
>>92

(defun f () 2)
(f) ; 2
(defmacro m () '(f))
(m) ; 2
(flet ((f () 3)) (m)) ; 3


(define (f) 2)
(f) ; 2
(define-syntax m (lambda (stx) (quote-syntax (f))))
(m) ; 2
(let ((f (lambda () 3))) (m)) ; 2

Name: Anonymous 2011-05-30 21:41

The jews are after me.

Name: Anonymous 2011-05-30 22:04

>>95
Your indentation is PIG DISGUSTING!

Name: Anonymous 2011-05-30 23:11

>>93
CLISP has its own non-standard extensions, SBCL has its own non-standard extensions...
...but only Scheme/Racket manages to make a whole new language from extensions!

Name: Anonymous 2011-05-30 23:19

>>95
Macro in LISP.

(defmacro aif (cond then else)
  `(let ((it ,cond))
     (if it ,then ,else)))


"Macro" in Scheme/Racket.

#lang racket
(require racket/stxparam)
 
(define-syntax-parameter it (lambda (stx) (raise-syntax-error 'anaphora "missed context" stx)))
 
(define-syntax-rule (aif cond then else)
  (let ([temp cond])
    (syntax-parameterize ([it (make-rename-transformer #`temp)])
                         (if temp then else))))

Name: Anonymous 2011-05-31 0:02

100 get, niggers.

Name: Anonymous 2011-05-31 1:08

>>77
yoba

(设置-定義機能 呼ぶ () (これ-機能))
(呼ぶ)

Name: Anonymous 2011-05-31 2:49

>>35
it uses goto which is by some considered bad. Why? Goto makes programs harder to read and analyze.

also, why not just:

for(int ii=0; ii<1000; ii++) {
    for(int jj=0; jj<1000; jj++) {
        for(int kk=0; kk<1000; kk++) {
            if(wantToBreak) {
                kk=1000;
                jj=1000;
                ii=1000;
            }
        }
    }
}

"breaks" from nested loops without the need of defining extra variable / checking it every loop

Name: Anonymous 2011-05-31 3:39

>>36
The guy who asked the question here. I guess I'll actually need to learn some LISP to figure what is up with that code, but regardles of that I thank you for the attempt.

Name: Anonymous 2011-05-31 3:45

>>102
Your C/C++ indendation is horrible! Use something like:

for (int ii=0
    ;ii<1000
    ;ii++)
   {for (int jj=0
        ;jj<1000
        ;jj++)
       {for (int kk=0
            ;kk<1000
            ;kk++)
           {if (wantToBreak)
              {kk=1000;
               jj=1000;
               ii=1000;}}}}

Name: Anonymous 2011-05-31 4:45

>>104
Why you little schemer

Name: Anonymous 2011-05-31 5:07

>>104
And this, my friends, is why people hate lisp.

Name: Anonymous 2011-05-31 5:09

>>106
He is not >>98-99

Name: Anonymous 2011-05-31 8:23

>>102
Changing the loop variable is argued by some to be even less readable. It's also rather stupid performance-wise, since you're forcing a comparison and I doubt the compiler would be able to replace that with a single jump (feel free to prove me wrong on this).

Name: Anonymous 2011-05-31 8:47

>>108
prove me wrong
$ cc -arch i386 -O3 -fomit-frame-pointer -std=gnu99 -S -o- -xc -
void prog()
{
    int wantToBreak=0;
    for(int ii=0; ii<1000; ii++) {
        for(int jj=0; jj<1000; jj++) {
            for(int kk=0; kk<1000; kk++) {
                if(wantToBreak) {
                    kk=1000;
                    jj=1000;
                    ii=1000;
                }
            }
        }
    }
}
^D    .section    __TEXT,__text,regular,pure_instructions
    .globl    _prog
    .align    4, 0x90

_prog:
    ret



.subsections_via_symbols

Name: Anonymous 2011-05-31 8:48

>>108
I doubt the compiler would be able to replace that with a single jump (feel free to prove me wrong on this).
Let's try!

[/prog/ 0]=> cat goto.c
#include <stdio.h>
main(){int i,j,k;
     for(i=0;i++<1000;)
      for(j=0;j++<1000;)
           for(k=0;k++<1000;)
            if(i==j==k==500)goto breakall;
            else printf("%d:%d:%d",i,j,k);
breakall: return 0;}
[/prog/ 0]=> cat faggot.c
#include <stdio.h>
main(){int i,j,k;
     for(i=0;i++<1000;)
      for(j=0;j++<1000;)
           for(k=0;k++<1000;)
            if(i==j==k==500)i=j=k=1000;
            else printf("%d:%d:%d",i,j,k);
     return 0;}
[/prog/ 0]=> gcc -O3 goto.c -S
[/prog/ 0]=> gcc -O3 faggot.c -S
[/prog/ 0]=> diff -u goto.s faggot.s
--- goto.s    2011-05-31 14:41:25.000000000 +0200
+++ faggot.s    2011-05-31 14:41:30.000000000 +0200
@@ -1,4 +1,4 @@
-    .file    "goto.c"
+    .file    "faggot.c"
     .section    .rodata.str1.1,"aMS",@progbits,1
 .LC0:
     .string    "%d:%d:%d"
@@ -46,7 +46,6 @@
     addl    $1, %edi
     cmpl    $1001, %edi
     jne    .L2
-.L7:
     leal    -12(%ebp), %esp
     xorl    %eax, %eax
     popl    %ebx


Same with -O2, -O1 e no optimization flag. I didn't expect gcc to be this smart, actually.

Clang with no optimization, instead, sets them to 1000, and optimizes to a jmp in -O1.


[/prog/ 1]=> gcc --version
gcc (GCC) 4.6.0 20110513 (prerelease)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[/prog/ 0]=> clang --version
clang version 2.9 (tags/RELEASE_29/final)
Target: i386-pc-linux-gnu
Thread model: posix

Name: Anonymous 2011-05-31 8:49

>>109
Use a printf to not optimize the whole loop away.

Name: Anonymous 2011-05-31 9:00

>>110
I didn't expect gcc to be this smart
I didn't expect /prog/rammers to be this stupid.  Try actually adding a break condition next time.

Name: Anonymous 2011-05-31 9:03

>>112
i++<1000;
j++<1000;
k++<1000;
            if(i==j==k==500)i=j=k=1000;

They are not enough?

Name: Anonymous 2011-05-31 11:15

>>111
Yeah. fputs() requires less computational power than printf()

Name: Anonymous 2011-05-31 12:05

>>114
I don't see any fputs call in >>109, stop trolling.

Name: Anonymous 2011-05-31 14:37

>>115
The comment was made in respond number 111 you fucking retard. Again, do you have ADD? Are you Jewish? Are you a jew with ADD? If so, then HCN might be for you!

Name: Anonymous 2011-05-31 14:38

>>116
YHBT FAGGOT

Name: Anonymous 2011-05-31 14:42

>>117
Shut up princess.

Name: Anonymous 2011-05-31 15:02

>>118
fuck off and die, fag

Name: Anonymous 2011-05-31 15:03

The jews are after me.

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