Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


#ActualCornstalks

Posted 19 April 2013 - 06:35 PM


I wonder what this thread would be like if people were talking about Racket/Scheme instead:

#lang racket
 
{define {foo bar}
  {if {= 5 bar}
      {display "It was 5\n"}
      {if {not {= 42 bar}}
          {display "It was something else\n"}
          {display "It was The Answer\n"}}}}
 
{foo 15}


o man, that's just insane.  is that actual regular syntax, or are you intentionally making it weird?


A little bit of both. Racket has the "feature" that it doesn't care about what kind of braces you use so long as the opening and closing match (so [] and {} and () are all the same). That code would normally be written using parentheses instead of curly braces, but I used curly braces to make it relevant to the thread.

Cornstalks: don't know any languages in the Scheme family, though what the heck is defining a scope or what is a scope in that family of languages?

Uhhh... the braces (which in normal code would be parentheses). In Racket/Scheme, the parentheses go before the function name, not after (so in C it's foo(), but in Racket it's (foo)). I won't go into the syntax too much, but there's sane scoping. It's just a weird syntax.

Just to show you what kind of horrible stuff you can do, you could write a simple program to print out "hi" a bunch of times, and instead of using the idiomatic parans, you can use non-idiomatic stuff:
(define (<>) (display "hi\n") <>)
[[[{{[{[{[{{(((({({({(({[[{{{((((<>))))}}}]]}))})})}))))}}]}]}]}}]]]
; prints ~32 lines of "hi"
So yeah... I don't care what kind of indentation you use in your C-style code, so long as you're consistent.

#2Cornstalks

Posted 19 April 2013 - 06:11 PM


I wonder what this thread would be like if people were talking about Racket/Scheme instead:

#lang racket
 
{define {foo bar}
  {if {= 5 bar}
      {display "It was 5\n"}
      {if {not {= 42 bar}}
          {display "It was something else\n"}
          {display "It was The Answer\n"}}}}
 
{foo 15}


o man, that's just insane.  is that actual regular syntax, or are you intentionally making it weird?


A little bit of both. Racket has the "feature" that it doesn't care about what kind of braces you use so long as the opening and closing match (so [] and {} and () are all the same). That code would normally be written using parentheses instead of curly braces, but I used curly braces to make it relevant to the thread.

Cornstalks: don't know any languages in the Scheme family, though what the heck is defining a scope or what is a scope in that family of languages?

Uhhh... the braces (which in normal code would be parentheses). In Racket/Scheme, the parentheses go before the function name, not after (so in C it's foo(), but in Racket it's (foo)). I won't go into the syntax too much, but there's sane scoping. It's just a weird syntax.

Just to show you what kind of horrible stuff you can do, you could write a simple program to print out "hi" a bunch of times, and instead of using the idiomatic parans like above, you can use non-idiomatic stuff:
(define (<>) (display "hi\n") <>)
[[[{{[{[{[{{(((({({({(({[[{{{((((<>))))}}}]]}))})})}))))}}]}]}]}}]]]
; prints ~32 lines of "hi"
So yeah... I don't care what kind of indentation you use in your C-style code, so long as you're consistent.

#1Cornstalks

Posted 19 April 2013 - 06:08 PM


I wonder what this thread would be like if people were talking about Racket/Scheme instead:

#lang racket
 
{define {foo bar}
  {if {= 5 bar}
      {display "It was 5\n"}
      {if {not {= 42 bar}}
          {display "It was something else\n"}
          {display "It was The Answer\n"}}}}
 
{foo 15}


o man, that's just insane.  is that actual regular syntax, or are you intentionally making it weird?


A little bit of both. Racket has the "feature" that it doesn't care about what kind of braces you use so long as the opening and closing match (so [] and {} and () are all the same). That code would normally be written using parentheses instead of curly braces, but I used curly braces to make it relevant to the thread.

Cornstalks: don't know any languages in the Scheme family, though what the heck is defining a scope or what is a scope in that family of languages?

Uhhh... the braces (which in normal code would be parentheses). In Racket/Scheme, the parentheses go before the function name, not after (so in C it's foo(), but in Racket it's (foo)). I won't go into the syntax too much, but there's sane scoping. It's just a weird syntax.

Things get funky when you start using lambda calculus (in Racket), though. Here's factorial in lambda calculus (using Church encoding):
((λ (f) (f (λ (f) (λ (z) (f (f (f (f (f z)))))))))
  (((λ (y) (λ (F) (F (λ (x) (((y y) F) x)))))
    (λ (y) (λ (F) (F (λ (x) (((y y) F) x))))))
   (λ (f)
     (λ (n)
       ((((((λ (n)
              ((n (λ (_) (λ (t) (λ (f) (f (λ (void) void))))))
               (λ (t) (λ (f) (t (λ (void) void))))))
            (((λ (n)
                (λ (m)
                  ((m
                    (λ (n)
                      (λ (f)
                        (λ (z)
                          (((n (λ (g) (λ (h) (h (g f)))))
                            (λ (u) z))
                           (λ (u) u))))))
                   n)))
              n)
             (λ (f) (λ (z) z))))
           (λ (_)
             ((λ (n)
                ((n (λ (_) (λ (t) (λ (f) (f (λ (void) void))))))
                 (λ (t) (λ (f) (t (λ (void) void))))))
              (((λ (n)
                  (λ (m)
                    ((m
                      (λ (n)
                        (λ (f)
                          (λ (z)
                            (((n (λ (g) (λ (h) (h (g f)))))
                              (λ (u) z))
                             (λ (u) u))))))
                     n)))
                (λ (f) (λ (z) z)))
               n))))
          (λ (_) (λ (t) (λ (f) (f (λ (void) void))))))
         (λ (_) (λ (f) (λ (z) (f z)))))
        (λ (_)
          (((λ (n) (λ (m) (λ (f) (λ (z) ((m (n f)) z))))) n)
           (f
            (((λ (n)
                (λ (m)
                  ((m
                    (λ (n)
                      (λ (f)
                        (λ (z)
                          (((n (λ (g) (λ (h) (h (g f)))))
                            (λ (u) z))
                           (λ (u) u))))))
                   n)))
              n)
             (λ (f) (λ (z) (f z))))))))))))
Now if you were a jerk, you would write the above using a horrible mix of braces and parans and screw up the indentation. Just to show you what kind of horrible stuff you can do, you could write a simple program to print out "hi" a bunch of times, and instead of using the idiomatic parans like above, you can use non-idiomatic stuff:
(define (<>) (display "hi\n") <>)
[[[{{[{[{[{{(((({({({(({[[{{{((((<>))))}}}]]}))})})}))))}}]}]}]}}]]]
; prints ~32 lines of "hi"

PARTNERS