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

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 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?

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