arclanguage / anarki

Community-managed fork of the Arc dialect of Lisp; for commit privileges submit a pull request.
http://arclanguage.github.io
Other
1.17k stars 160 forks source link

Interop seamlessly with racket #161

Open shawwn opened 5 years ago

shawwn commented 5 years ago

This PR illustrates a way to interop seamlessly between racket and arc. More details. Most of the tests pass.

(Not really intended to be merged. I'm doing something similar in https://github.com/laarc/laarc so I wanted to show how it could be done in anarki.)

arc> (sequence->list "foo")
'(#\f #\o #\o)

arc> (sequence->list (in-range 10 0 -0.5))
'(10
  9.5
  9.0
  8.5
  8.0
  7.5
  7.0
  6.5
  6.0
  5.5
  5.0
  4.5
  4.0
  3.5
  3.0
  2.5
  2.0
  1.5
  1.0
  0.5)

arc> (each n (in-range 10 0 -0.5) (out n (expt n 2)))
'((10 100)
  (9.5 90.25)
  (9.0 81.0)
  (8.5 72.25)
  (8.0 64.0)
  (7.5 56.25)
  (7.0 49.0)
  (6.5 42.25)
  (6.0 36.0)
  (5.5 30.25)
  (5.0 25.0)
  (4.5 20.25)
  (4.0 16.0)
  (3.5 12.25)
  (3.0 9.0)
  (2.5 6.25)
  (2.0 4.0)
  (1.5 2.25)
  (1.0 1.0)
  (0.5 0.25))

; use racket's sort
arc> (|sort| '(a b "foo" 21) (compare > string))
'("foo" b a 21)

arc> (|sort| '(a b "foo" 21) (compare < string))
'(21 a b "foo")

arc> (sequence->list (in-producer (thunk (bytes-ref (crypto-random-bytes 1) 0)) (%do [< _ 42])))
'(56 119)

arc> (sequence->list (in-producer (thunk (bytes-ref (crypto-random-bytes 1) 0)) (%do [< _ 42])))
'(192 163 45 163 79 184 218 105 67 67 240 228)

arc> (sequence->list (in-producer (thunk (bytes-ref (crypto-random-bytes 1) 0)) (%do [< _ 42])))
'(189)

arc> (sequence->list (in-producer (thunk (bytes-ref (crypto-random-bytes 1) 0)) (%do [< _ 42])))
'(141 148 243)

arc> (define (1+ (n 0)) (+ n 1))

arc> (1+ 21)
22

arc> (1+)
1

arc> (1+:1+:1+ 21)
24
akkartik commented 5 years ago

The description at http://arclanguage.org/item?id=21163 is super useful to understanding the intent of this PR. Thanks!

rocketnia commented 5 years ago

Here's a link to the Arc Forum thread since some discussion has happened there: http://arclanguage.org/item?id=21162