Ai Dreams Forum

Member's Experiments & Projects => General Project Discussion => Topic started by: Zero on June 26, 2017, 10:35:41 am

Title: Common project: learn Racket programming language
Post by: Zero on June 26, 2017, 10:35:41 am
Hi guys,

I want to add Scheme to my toolbox. I began reading Structure and Interpretation Of Computer Programs (http://deptinfo.unice.fr/~roy/sicp.pdf), but now I want to get my hands dirty.

Racket seems to be a good programming language. Who wants to learn Racket with me? We would read the Racket Guide (http://docs.racket-lang.org/guide/index.html) at the same time, step by step, discuss examples, try things, find other tutorials, ...etc.

So, who's in?  :P
Title: Re: Common project: learn Racket programming language
Post by: Zero on June 27, 2017, 09:05:54 am
I'm currently swimming in Racket. Honestly I've rarely seen such a neat and powerful language.

EDIT:
Look ma!
Code: [Select]
(define make-counter
  (lambda ()
    (let ((n 0))
      (lambda () (set! n (add1 n)) n))))

> (define c1 (make-counter))
> (define c2 (make-counter))
> (c1)
1
> (c1)
2
> (c1)
3
> (c2)
1
> (c2)
2
> (c1)
4
>

Come on guys, water is fresh and fishes are beautiful!!!
Title: Re: Common project: learn Racket programming language
Post by: Zero on June 28, 2017, 09:53:23 pm
Using Nodejs REPL from inside Racket:
Code: [Select]
> (define-values (p out in err)
    (subprocess #f #f #f "C:/Hangar/nodejs/node.exe"))
> (display "console.log('hello from node');" in)
> (close-output-port in)
> (read-line out)
"hello from node"
>
Title: Re: Common project: learn Racket programming language
Post by: infurl on June 28, 2017, 11:05:54 pm
Honestly I've rarely seen such a neat and powerful language.

How many languages have you seen?
How many languages have you been using for more than five years?
Title: Re: Common project: learn Racket programming language
Post by: Zero on June 29, 2017, 07:41:06 am
Am I supposed to answer gently?  :)

EDIT:

I've seen C, C++, Ada, Python, Prolog, Io, Joy, Forth, Cat, Raven, Om, Brainfuck, Unlambda, False, Thue, Julia, Euphoria, Lua, Angelscript, Scriptbasic, Logo, Smalltalk and others.

I've been using for more than 5 years Locomotive Basic, Turbo Pascal 6, Perl, Javascript, VBA.

What languages have you been using for more than 5 years, infurl?

In your opinion, which languages are more powerful and neat?
Title: Re: Common project: learn Racket programming language
Post by: Art on June 29, 2017, 03:30:50 pm
The nice thing I've noticed about "Standards" is that there are so many from which to choose!  ;)

For your amusement or personal satisfaction:

https://en.wikipedia.org/wiki/List_of_programming_languages_by_type (https://en.wikipedia.org/wiki/List_of_programming_languages_by_type)
Title: Re: Common project: learn Racket programming language
Post by: Zero on June 29, 2017, 04:50:57 pm
Yes, it depends on what you're planning to do. Racket is good for me, since I like to play with languages syntax and semantics (one of my favorite (serious) toys is pegjs (https://pegjs.org/), a js parsing expression grammar generator).

I can't imagine how many tera-man-hours this programming languages jungle represents...  :o
Title: Re: Common project: learn Racket programming language
Post by: ivan.moony on June 29, 2017, 07:03:22 pm
There is some vibe in lisp-ish languages that has always been fascinating to me.
Title: Re: Common project: learn Racket programming language
Post by: infurl on June 30, 2017, 02:11:15 am
There is some vibe in lisp-ish languages that has always been fascinating to me.

You are surely right about that. I was programming with Common Lisp professionally for more than 10 years, wrote some very big projects some of which are still running big businesses.

In the end I had to stop using Common Lisp for my AI work because while I could often produce a kickass solution with a few days work, I'd then have to waste months trying to make it fast enough for the intended purpose. It turned out to be a lot quicker to just write it in C in the first place, even if it took three weeks instead of three days to get something working. I still miss Common Lisp though, and would like to have a good reason to go back to it.
Title: Re: Common project: learn Racket programming language
Post by: Zero on June 30, 2017, 09:28:59 am
And you didn't find a variant of lisp that would be fast enough? Are they all too slow for your requirements? That's sad... Isn't there a lisp with JIT compilation somewhere?
Title: Re: Common project: learn Racket programming language
Post by: infurl on June 30, 2017, 10:12:32 am
JIT compilers? Haha that's not the issue. There are a number of excellent optimising compilers for Common Lisp, even open source ones such as Steel Bank Common Lisp (SBCL) which you can get from http://www.sbcl.org/

No, the problem is memory management. When you are working with many gigabytes of memory, garbage collection becomes prohibitively expensive and even reusing the same algorithms, you can make enormous performance gains by taking over memory management in ways that are more closely attuned to the problem that you are solving.
Title: Re: Common project: learn Racket programming language
Post by: Zero on June 30, 2017, 10:51:29 am
Ok I understand.
Title: Re: Common project: learn Racket programming language
Post by: Zero on July 01, 2017, 09:46:00 am
A little Datalog in my Racket:
Code: [Select]
#lang racket

(require datalog)

(define geo (make-theory))

(datalog geo
         (! (edge a b))
         (! (edge b c))
         (! (edge a d))
         (! (edge b d))
         (! (edge d e))
         (! (edge d f))
         (! (edge f g))
         (! (:- (path X Y) (edge X Y)))
         (! (:- (path X Y) (edge X Z) (path Z Y))))

> (datalog geo (? (path X g)))
'(#hasheq((X . f)) #hasheq((X . a)) #hasheq((X . b)) #hasheq((X . d)))

Title: Re: Common project: learn Racket programming language
Post by: Zero on July 04, 2017, 11:20:20 am
Remember how stuff was defined...
Code: [Select]
#lang racket

(define user-function (make-hash))

(define (definition id)
  (hash-ref user-function id))

(define-syntax-rule (define/keep id expr)
  (begin
    (hash-set! user-function 'id 'expr)
    (define id expr)))


> (define/keep double (lambda (x) (* 2 x)))
> (double 5)
10
> (definition 'double)
'(lambda (x) (* 2 x))
> (eval (list (definition 'double) 10))
20
>
Title: Re: Common project: learn Racket programming language
Post by: Zero on July 16, 2017, 02:36:47 pm
Well, I'm fed-up.

I think it really became obvious when I had to explicitly state that I wanted my struct to be mutable. I don't feel the sexy' anymore.

And by the way, Javascript is homoiconic too. Yeah, the code can be represented by strings! Or the AST by an object.

Lispish feels old. No offence, it's purely personal taste. And, starting a lot of parens at the beginning of something, whitout knowing which goes where, really doesn't feel right.
Title: Re: Common project: learn Racket programming language
Post by: WriterOfMinds on July 17, 2017, 12:46:49 am
How broadly beyond Racket would you say these complaints apply?
Title: Re: Common project: learn Racket programming language
Post by: korrelan on July 17, 2017, 11:09:43 am
Quote
I don't feel the sexy' anymore.

That made me smile lol. 

So many languages and all tailored towards the original writers’ needs/ requirements.  I tend to stick with what’s quickest and easiest for me; which is obviously down to my experience and time invested learning the language and it’s foibles.

I envy your ability to sample each language and I enjoy your ‘reviews’; I just wouldn't’ have the patience lol. 

Is coding language exploring a hobby or are you looking for the ‘holy grail’ of languages?

:)
Title: Re: Common project: learn Racket programming language
Post by: Zero on July 17, 2017, 11:58:13 am
Quote
How broadly beyond Racket would you say these complaints apply?

The parens thing is about s-expressions, and the mutability thing is about functional languages. But here I'm just talking about Racket, because there are other ways to use s-expressions, and other ways to handle immutability. Let's be fair: it's about Racket only.

Quote
Is coding language exploring a hobby or are you looking for the ‘holy grail’ of languages?

Yeah, it's a real passion. I love esolangs (https://esolangs.org/wiki/Main_Page) for instance. I love creating syntaxes and semantics, usually with PEGjs and node/browser for fast prototyping. I'm not sure there's a holy-grail language. Who knows!
Need to eat now!
Title: Re: Common project: learn Racket programming language
Post by: 8pla.net on July 19, 2017, 03:56:39 pm
So, the syntax tree, in Racket, is abstract?
Title: Re: Common project: learn Racket programming language
Post by: Zero on July 19, 2017, 04:12:41 pm
What do you mean ?
Title: Re: Common project: learn Racket programming language
Post by: 8pla.net on July 21, 2017, 02:18:13 am
I mean to ask whether the Racket programming language is an AST (Abstract Syntax Tree)?
Title: Re: Common project: learn Racket programming language
Post by: Zero on July 21, 2017, 09:24:56 am
The Racket programming language is a programming language. Its syntax can be represented by an AST. Does it answer your question?