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

★ /prog/ Challenge Vol. 5 ★

Name: Anonymous 2010-06-11 23:51

The challenge suggestion thread was too busy going nowhere, and I feel like writing some code, so here is a /prog/ challenge.

THE CHALLENGE:
Design a toy programming language. You may implement either a compiler or interpreter, and you may write the implementation in any language of your choosing.

Post the source code to your implementation as well as programs in your language to accomplish at least two of the following tasks, plus one ``wild card'' program not listed here.

    • Factorial calculator
    • Fibonacci sequence generator
    • Prime number sieve (e.g. Eratosthenes, Atkin, etc.)
    • fgrep (output lines of input containing a given string)
    • Caesar cipher
    • Simple interactive calculator
    • Tic-tac-toe (AI not required)
    • The game of Nim (http://en.wikipedia.org/wiki/Nim)

Entries must be submitted prior to 2010-06-21 00:00, which gives one full week and two weekends. Judgment will be in three categories: presentation and cleverness of designed language, clarity of implementation, and overall usefulness/entertainment/trolling value of the ``wild card'' program.

Winner will receive ten Susscoins, to be transferred via /prog/mail.

Name: Anonymous 2010-06-22 1:16

>>149
at least one was not imperative.

Name: Anonymous 2010-06-22 10:36

>>161
How so?

Name: Anonymous 2010-06-22 18:21

>>161
that stack one is a concatenative language.

Name: Anonymous 2010-06-22 18:26

Codan actually has a proof of Touring completeness. That's nice.

http://esolangs.org/wiki/Codan#Turing_completeness

Name: Anonymous 2010-06-22 18:46

>>164
Turd solves NP complete problems in linear time

Name: Anonymous 2010-06-22 20:27

>>163
Every one of the languages here was implemented in C, Python, or Perl.

Name: Anonymous 2010-06-22 20:28

Name: Anonymous 2010-06-23 0:28

>>166
ghc is written in c, but that doesn't make haskell imperative.

Name: Anonymous 2010-06-23 1:32

>>167
To be fair, Xarn wrote the Codan article himself, and Turd is a work in progress.

Name: Anonymous 2010-07-16 16:22

I don't understand codan...

It seems to me to be just a way to put unicode into variables.

Name: Anonymous 2010-09-18 10:54

Not enough Xarn on /xarn/ these days.

    /´. _, -―-、ヽ、
  ./  l´[☆ィTfヘマ、 ヽ
 |  | |ィケリノ |ト}!l|
 | _| レァ予  伝yリ|    ,..、
  | fr| 《{_丿   Ljハ∥  _,ノ/`il  /
  | ゞ||'''  r‐ァ`,ツイイ´  ハ il      PROGGLES
 |  | 「`}T 云'I「|{ {::::{ V リ   \
 || N {`ヾー弋イノ`衣√`ヾノ
  从 | l! Y   Qヘ\イ乍}
    `ヽハ l〉    Y´ア´
      レ´       「´

Name: Anonymous 2010-09-18 11:54

>>171
BUMP MY NECROFETIC ANUS

Name: Anonymous 2010-09-18 14:14

>>171
Sadly, I have to agree with you.

Name: Anonymous 2010-09-19 9:38

>>158
New Turd release, now.

Name: Anonymous 2010-09-19 10:01

>>174
sorry, turd is untouched since then. the one letter variable system was not right for the perfect language that i will one day write. also i wasn't happy with \n terminated lines as it hindered the writing of ugly terse one-liners. and also it was a massive hack designed at the keyboard.

Name: Anonymous 2010-09-19 12:26

A beautiful, inspiring thread.

Name: Anonymous 2010-11-15 0:25

Name: Anonymous 2011-03-03 5:13

prog was good once

Name: Anonymous 2011-03-03 5:41

>>178
Sup, XARN

Name: Anonymous 2011-03-03 5:44

It's not complete and I'm still working on the syntax.

(require parser-tools/yacc
         parser-tools/lex
         (prefix-in : parser-tools/lex-sre))


(define-empty-tokens infix-operators (cons append + * - ^ / // > < >= <= = :=))

(define-empty-tokens separators (comma open-paren close-paren
                                       open-bracket close-bracket
                                       open-brace close-brace
                                       => assign eof))

(define-empty-tokens keywords (ellipsis eq? eqv? equal? quote lambda let let* letrec in nil if then else cond))

(define-tokens values (lisp number identifier string))

(define-lex-abbrevs
  (%digit (:/ #\0 #\9))
  (%idchr (:or alphabetic "?" "!" "_"))
  (%string (:: #\" (complement (:: any-string #\" any-string)) #\"))
  (%number (:or (:+ %digit)
                (:: (:+ %digit) #\. (:+ %digit))))
  (%identifier (:: %idchr (:* (:or %digit %idchr)))))

(define lexit
  (lexer
   ((eof) 'eof)
   ((:: "--" (complement (:: any-string #\newline any-string)) #\newline) (lexit input-port))
   ((:: "{-" (complement (:: any-string "-}" any-string)) "-}") (lexit input-port))
   ((:or #\tab #\space #\newline) (lexit input-port))
   ((:or "=" ">=" "<=" ">" "<" "^" ":="
         "+" "*" "-" "/" "//") (string->symbol lexeme))
   ((:or "let" "let*" "letrec" "in" "if" "cond" "=>" "eq?" "eqv?" "equal?"
         "then" "else" "nil") (string->symbol lexeme))
   ((:or "λ" "lambda") (token-lambda))
   ((:or "'" "quote") (token-quote))
   ("..." (token-ellipsis))
   (":" (token-cons))
   ("++" (token-append))
   ("," (token-comma))
   ("{" (token-open-brace))
   ("}" (token-close-brace))
   ("[" (token-open-bracket))
   ("]" (token-close-bracket))
   ((:: "#(" any-string ")#") (token-lisp (substring lexeme 2 (- (string-length lexeme) 2))))
   ("(" (token-open-paren))
   (")" (token-close-paren))
   (%number (token-number (string->number lexeme)))
   (%string (token-string lexeme))
   (%identifier (token-identifier (string->symbol (regexp-replace* #rx"_" lexeme "-"))))))

(define parseit
  (parser
   (start top)
   (end eof)
   (tokens infix-operators separators keywords values)
   (error (λ x (displayln x)))
  
   (precs (right quote)
          (left + *)
          (left - / //)
          (right ^)
          (right cons append)
          (nonassoc >= > < <=)
          (right =)
          (right :=)
          (right comma))
  
   (grammar
    (top (() #f)
         ((stmt) $1)
         ((stmts) `(begin ,@$1))
         )
   
    (stmts
     ((stmt) `(,$1))
     ((stmt stmts) `(,$1 ,@$2)))
   
    (value
     ((number) $1)
     ((string) $1)
     ((fun) $1)
     ((nil) ''())
     ((list) `(quote ,$1))
     ((quote expr) `(quote ,$2)))
   
    (values
     ((value) `(,$1))
     ((value comma values) `(,$1 ,@$3)))
   
    (list
     ((open-bracket close-bracket) ''())
     ((open-bracket values close-bracket) `(,@$2)))
   
    (stmt
     ((expr) $1)
     ((identifier := expr) `(define ,$1 ,$3))
     ((identifier = expr) `(set! ,$1 ,$3)))
   
    (expr
     ((value) $1)
     ((fun) $1)
     ((lisp) $1)
     ((let bindings in expr) `(let ,$2 ,$4))
     ((let* bindings in expr) `(let* ,$2 ,$4))
     ((letrec bindings in expr) `(letrec ,$2 ,$4))
     ((cond condcases) `(cond ,@$2))
     ((if expr then expr) `(if ,$2 ,$4 #f))
     ((if expr then expr else expr) `(if ,$2 ,$4 ,$6))
     ((open-paren expr close-paren list-of-exprs) `(,$2 ,@$4))
     ((fun list-of-exprs) `(,$1 ,@$2))
     ((- expr) `(- ,$2))
     ((expr + expr) `(+ ,$1 ,$3))
     ((expr * expr) `(* ,$1 ,$3))
     ((expr / expr) `(/ ,$1 ,$3))
     ((expr // expr) `(quotient ,$1 ,$3))
     ((expr ^ expr) `(expt ,$1 ,$3))
     ((expr - expr) `(- ,$1 ,$3))
     ((expr > expr) `(> ,$1 ,$3))
     ((expr < expr) `(< ,$1 ,$3))
     ((expr >= expr) `(>= ,$1 ,$3))
     ((expr <= expr) `(<= ,$1 ,$3))
     ((expr = expr) `(= ,$1 ,$3))
     ((expr eq? expr) `(eq? ,$1 ,$3))
     ((expr eqv? expr) `(eqv? ,$1 ,$3))
     ((expr equal? expr) `(equal? ,$1 ,$3))
     ((expr cons expr) `(cons ,$1 ,$3))
     ((expr append expr) `(append ,$1 ,$3))
     ((open-paren expr close-paren) $2)
     ((open-brace exprs close-brace) `(begin ,@$2))
     ((lambdaexpr) $1)
     )
   
    (exprs
     ((expr) `(,$1))
     ((expr exprs) `(,$1 ,@$2)))
   
    (lambdaexpr ((lambda list-of-identifiers expr) `(lambda ,$2 ,$3)))
   
    (list-of-exprs
     ((open-paren close-paren) '())
     ((open-paren cexprs close-paren) $2))
   
    (cexprs
     ((expr) `(,$1))
     ((expr comma cexprs) `(,$1 ,@$3)))
   
    (identifiers
     (() '())
     ((identifier) `(,$1))
     ((identifier ellipsis) $1)
     ((identifier comma identifiers) `(,$1 ,@$3)))
   
    (list-of-identifiers
     ((open-paren identifiers close-paren) $2))
   
    (fun
     ((identifier) $1)
     ((open-paren + close-paren) '+)
     ((open-paren * close-paren) '*)
     ((open-paren / close-paren) '/)
     ((open-paren // close-paren) 'quotient)
     ((open-paren - close-paren) '-)
     ((open-paren > close-paren) '>)
     ((open-paren < close-paren) '<)
     ((open-paren = close-paren) '=)
     ((open-paren >= close-paren) '>=)
     ((open-paren <= close-paren) '<=)
     ((open-paren eq? close-paren) 'eq?)
     ((open-paren eqv? close-paren) 'eqv?)
     ((open-paren equal? close-paren) 'equal?)
     ((open-paren ^ close-paren) 'expt)
     ((open-paren cons close-paren) 'cons)
     ((open-paren append close-paren) 'append))
   
    (condcases
     ((condcase) `(,$1))
     ((condcase condcases) `(,$1 ,@$2)))
   
    (condcase
     ((open-bracket expr close-bracket) `(,$2))
     ((open-bracket expr expr close-bracket) `(,$2 ,$3))
     ((open-bracket expr => fun close-bracket) `(,$2 => ,$4))
     ((open-bracket else expr close-bracket) `(else ,$3)))
   
    (bindings
     ((binding) `(,$1))
     ((binding comma bindings) `(,$1 ,@$3)))
   
    (binding
     ((identifier = expr) `(,$1 ,$3))))))

(define (parse-port ip)
  (port-count-lines! ip)
  (letrec ((one-line
            (lambda ()
              (let ((result (parseit (lambda () (lexit ip)))))
                (if result result (one-line))))))
    (one-line)))
(define (parse-string s)
  (parse-port (open-input-string s)))

(parse-string "
fact := λ(x) letrec loop = λ(x,n) if zero?(x) then n else loop(x-1,x*n) in loop(x,1)
fibs := λ(x) letrec loop = λ(a,b,x,r) if zero?(x) then reverse(a:r) else loop(b,a+b,x-1,a:r) in loop(0,1,x,nil)
")
;'(begin
;   (define fact (lambda (x) (letrec ((loop (lambda (x n) (if (zero? x) n (loop (- x 1) (* x n)))))) (loop x 1))))
;   (define fibs (lambda (x) (letrec ((loop (lambda (a b x r) (if (zero? x) (reverse (cons a r)) (loop b (+ a b) (- x 1) (cons a r)))))) (loop 0 1 x '())))))

Name: Anonymous 2011-03-03 6:36

>>180
i think you missed the entry date

Name: Anonymous 2011-03-03 6:40

>>181
I'm prepared for the next one if there will be another

Name: Anonymous 2011-03-03 10:36

>>182
Why the hell would a challenge repeat itself?

Name: Anonymous 2011-03-03 10:38

>>183
So that the room will be empty.

Name: Anonymous 2011-03-03 12:06

>>184
A U T I S M

Name: Anonymous 2011-03-03 21:11

DICKS

Name: Anonymous 2011-03-04 4:27

lol dicks

Name: Anonymous 2011-03-04 5:48

<--- check em

Name: Anonymous 2011-03-04 7:11

>>188
Not nice. You have LeadingOne disease. And autism.

Name: Anonymous 2012-10-03 6:00

/prog/ Challenge
Why don't we have such threads anymore?

Name: Harry Pothead 2012-10-03 6:15

The game of Nim (http://en.wikipedia.org/wiki/Nim)
Da flying nimbus.

Name: Anonymous 2012-10-03 6:51

>>190
Because everyone who knew enough about programming left this boards long ago.

Only trolls and clueless first-grade CS students remain here.

Name: Anonymous 2012-10-03 11:50

>>192
Are you a troll or a clueless first-grade CS student?

Name: Anonymous 2012-10-03 13:20

>>192
Expert programmer here, I wrote an ANSI C compiler when I was 9.

Name: Anonymous 2012-10-03 14:23

>>194
I masturbated to Yukari when I was 8.

Name: Anonymous 2012-10-03 14:30

>>194
ANSI C a shit. You should be ashamed of yourself.

Name: Anonymous 2012-10-03 14:50

>>196
As soon as I finished it, I realized C was undefined shit, so I wrote a JIT-accelerated Lisp interpreter in assembly; it took me a bit longer than a week to complete it because I had promised Gerry to correct the final draft of SICP and it was chock-full of stupid mistakes.

Name: Anonymous 2012-10-03 16:23

>>197
I want to suck your dick.

Name: Anonymous 2012-10-03 21:26

>>190
Because you don't bother to start them. We had http://dis.4chan.org/read/prog/1337015808 only a few months ago. /prog/ may be full of Redditors now, but it's still possible to do this sort of thing.

Name: Anonymous 2012-10-03 22:43

>>198
HEY I WAS THERE FIRST!

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