Klambda type function

170 views
Skip to first unread message

Matúš Kmiť

unread,
Nov 17, 2017, 10:09:14 AM11/17/17
to Shen
Hi

I am porting Shen to Elixir (Erlang).

Function "type" counts among one of the Klambda primitives, but I can't figure out what it does.


Greetings,
Matus

Bruno Deferrari

unread,
Nov 17, 2017, 10:13:38 AM11/17/17
to qil...@googlegroups.com
Nothing, it just tags the type of the expression so that the compiler can take advantage of it when producing code if it can (no port makes use if it for now afaik).

You can compile it away if you want and replace it with the inner expression (type <expression> <type>) -> <expression>

--
You received this message because you are subscribed to the Google Groups "Shen" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qilang+unsubscribe@googlegroups.com.
To post to this group, send email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

Matúš Kmiť

unread,
Nov 17, 2017, 11:50:14 AM11/17/17
to Shen
Ok, thanks.

Robert Koeninger

unread,
Nov 17, 2017, 1:25:51 PM11/17/17
to Shen
I forgot I left a node in there: "TODO: Doesn't seem to require an implemention."

The type function isn't used in the klambda version of the kernel sources anywhere. Either shen->kl should provide these type hints or the function should just be removed from the porting requirements.

Bruno Deferrari

unread,
Nov 17, 2017, 1:30:06 PM11/17/17
to qil...@googlegroups.com
It is still a requirement even if the kernel itself doesn't come with type annotations by default, because an user may enable the `optimise` flag, resulting in Kl code with such annotations.

Example:

Shen, copyright (C) 2010-2015 Mark Tarver
www.shenlanguage.org, Shen 20.1
running under Scheme, implementation: chez-scheme
port 0.16 ported by Bruno Deferrari


(0-) (optimise +)
true

(1-) (tc +)
true

(2+) (define add-nums      
       { number --> number --> number }
       X Y -> (+ X Y))
add-nums : (number --> (number --> number))

(3+) (ps add-nums)
[defun add-nums [V1363 V1364] [+ [type V1363 number] [type V1364 number]]] : (list unit)

--
You received this message because you are subscribed to the Google Groups "Shen" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qilang+unsubscribe@googlegroups.com.
To post to this group, send email to qil...@googlegroups.com.
Visit this group at https://groups.google.com/group/qilang.
For more options, visit https://groups.google.com/d/optout.



--
BD

Robert Herman

unread,
Dec 30, 2017, 12:52:40 PM12/30/17
to Shen
Matus,

I was playing with LFE (Lisp Flavoured Erlang), so I will be interested in how you get along with a Shen port to Erlang or Elixir.

I would think you would want to go right for Erlang, since that is what Elixir compiles to and skip that layer. Also Robert Virding, a co-creator of Erlang with Joe Armstrong, did a lot of work on LFE. He brought as much Lisp to the table that he could, but I am guessing the fit is not ideal.

Good luck, and thanks for contributing to Shen.

Happy New Year!

Rob


On Friday, November 17, 2017 at 10:09:14 AM UTC-5, Matúš Kmiť wrote:

Matúš Kmiť

unread,
Dec 30, 2017, 2:44:36 PM12/30/17
to Shen
Hi Rob

I have heard about LFE before. Thanks for bringing it to the table, maybe I should take a look at it again.

There are many different possibilities how to port Shen to Elixir/Erlang. Because Elixir code is represented in its own data structure similar to a lisp list, I was first thinking of using this fact to an advantage and translate the Klambda code data to a Elixir one and then either interpret it on the go or compile it to Elixir or even Erlang itself.

I have decided to write an interpreter first to get acquainted with Klambda and Elixir/Erlang platform. It is nearly ready, I have just finished implementing currying and partial application. In the course of its writing, somehow I abandoned the idea mentioned above and just interpret the particular primitive functions ad-hoc in no uniform manner.

As soon as it is done and my knowledge of Klambda and Elixir/Erlang is solid, I will probably leave it as is, without optimisation and move on to writing a compiler. As far as my current understanding goes, Elixir is more or less only a syntactic sugar for Erlang and this layer shouldn't have a big penalty in terms of performance. I think one can even compile the Elixir code to the Erlang VM byte code. Since Elixir is quite popular at the moment and the FFI for its underlying Erlang platform is very straightforward, idiomatic and intuitive, I think it would be wiser to host Shen on Elixir...


Greetings,
Matus

Robert Herman

unread,
Jan 2, 2018, 9:19:19 AM1/2/18
to Shen
Your progress sounds promising. Good luck.

I agree with you that Elixir has one the popularity contest with LFE. I think it is because all of the Ruby devs find the syntax pleasing. I personally prefer straight up Erlang.

Robert Virding has implemented other ports to Erlang, but I think he is a Lisper at heart, and was really looking for LFE to take off.

Happy New Year!

Matúš Kmiť

unread,
Jan 3, 2018, 6:23:37 AM1/3/18
to Shen
Happy New Year too.

Translating Klambda to LFE, ist that what you would basically suggest...?

Matúš Kmiť

unread,
Mar 19, 2018, 10:01:21 AM3/19/18
to Shen
I took the ball you threw Rob. I am no working on the following implementation (compiled): Shen -> Klambda -> LFE -> Erlang VM (.beam).

I somewhat finished the Elixir port (interpreted), with only 1 failing test, but veeeeery slow, unusable actually. And I also kind of lost motivation for further optimisation after taking look at LFE :-)

Matus Kmit

unread,
Mar 19, 2018, 10:17:21 AM3/19/18
to qil...@googlegroups.com
typo correction:

I am *now* working...

--
You received this message because you are subscribed to a topic in the Google Groups "Shen" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/qilang/278jz92RQVM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to qilang+un...@googlegroups.com.
signature.asc
Reply all
Reply to author
Forward
0 new messages