slurp records from a module

50 views
Skip to first unread message

arjan

unread,
Mar 22, 2016, 11:02:04 AM3/22/16
to Lisp Flavoured Erlang
Hi.
I'm having problems with loading records from a file:

(lfe 1.0)
(defmodule rec)

(defrecord person
  name
  address
  age
)


(defun dp (x) (* 2 x))

in the shell:

> (slurp "rec.lfe")
#(ok rec)
> (dp 4)
8
> (make-person name "Arjan" age 27)
exception error
: #(unbound_func #(make-person 4))


while it's all ok if a record is defined directly in the shell.
Am i doing something wrong??

Eric Bailey

unread,
Mar 22, 2016, 11:38:39 AM3/22/16
to lisp-flavo...@googlegroups.com
I’m able to reproduce the issue.

The traditional approach would be more like this:

    $ find . -name '*.lfe' -printf '\n===> %p\n' -exec cat {} \;

    ===> ./include/person.lfe
    (defrecord person
      name
      address
      age)

    ===> ./src/example.lfe
    (defmodule example
      (export (dp 1)))

    (include-lib “include/person.lfe")

    (defun dp (x) (* 2 x))



Then in an LFE shell you can do:

    > (include-lib "include/person.lfe")
    set-person-age
    > (make-person name "Arjan" age 27)
    #(person "Arjan" undefined 27)


Perhaps someone else can elucidate the differences between slurp and include-{lib,file} in this case.


Hope that helps,

Eric


--
You received this message because you are subscribed to the Google Groups "Lisp Flavoured Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-e...@googlegroups.com.
To post to this group, send email to lisp-flavo...@googlegroups.com.
Visit this group at https://groups.google.com/group/lisp-flavoured-erlang.
For more options, visit https://groups.google.com/d/optout.

arjan

unread,
Mar 22, 2016, 11:48:34 AM3/22/16
to Lisp Flavoured Erlang
Thanks.
Yes that would be very helpful.

In fact there is another way in the user guide intro:
; if a module is in your path(shell path) you ca load it through

> (l 'rec)
(#(module rec
))
>


Eric Bailey

unread,
Mar 22, 2016, 11:55:29 AM3/22/16
to lisp-flavo...@googlegroups.com
IIRC (l ‘module-name) is for (re-)loading .beam files on the code path.

So for that to work here, you’d have to first do

    $ mkdir -p ebin
    $ lfec -o ebin src/example.lfe


Then in an LFE shell you could do:

    > (l ‘example)
    ok
    > (example:dp 4)
    8


Robert Virding

unread,
Mar 22, 2016, 12:12:18 PM3/22/16
to lisp-flavo...@googlegroups.com
Arjan the basic reason for your problem is with the new module handling. I will check what is going on. Macros should also be loaded.

The idea behind slurp is that you can load in a whole file and get access to all the functions and macros in that file. One (necessary) restriction with the multi-module files is that only the first module in the file will be slurped, the others will be ignored. Otherwise you could end up with a right mess.

Yes, the shell l command just (re)loads a compiled .beam file. It is useful for reloading modules compiled "somewhere else".

Robert

arjan

unread,
Mar 22, 2016, 12:45:03 PM3/22/16
to Lisp Flavoured Erlang
The fact is that "slurp" makes the learnig process easier;
one doesn't have to know all that much what is going on
under the hood.
I am aware that one has to know a little bit of erlang too,
that's why I'm starting to learn them(erlang/lfe) in parallel.

Robert Virding

unread,
Mar 22, 2016, 4:24:01 PM3/22/16
to Lisp Flavoured Erlang
One problem with slurping is that the functions in the module become purely local to the REPL so you can't call them from another module. You need to compile them for that.

Robert

Robert Virding

unread,
Mar 25, 2016, 2:07:08 PM3/25/16
to Lisp Flavoured Erlang
Arjan the latest commit in the develop branch contains a fix which means that when you slurp a file you also get all the macros. Please test it ofr me and if all seems well it will come in the next release, 1.0.1, which is coming soon.

This was actually not a bug but a decision I made, which wasn't so good.

Robert

Eric Bailey

unread,
Mar 25, 2016, 4:29:44 PM3/25/16
to lisp-flavo...@googlegroups.com
Robert, it seems included (include-{lib,file}) macros now get exported in modules. I'm not sure if this is new since your fixes or not, but is that the desired behaviour? Overall, I think it's cool and it solves the same problem as Kyla's wrapper function, but it seems it might be a bit of a surprise.

Eric




arjan

unread,
Mar 26, 2016, 10:29:24 AM3/26/16
to Lisp Flavoured Erlang
It works like charm.
Thanks Robert.
By the way, this is my first programming experience (done very little c in university) and I'm loving it.
Thanks again.

Eric Bailey

unread,
Mar 26, 2016, 3:07:29 PM3/26/16
to lisp-flavo...@googlegroups.com
Re: Arjan. Awesome, happy hacking!

Re: my message. I think what I meant was it's showing up in the docs beam chunk. Also s/Kyla/kla/

Eric




--

Robert Virding

unread,
Mar 26, 2016, 6:08:59 PM3/26/16
to Lisp Flavoured Erlang
No, the macro including is very simplistic in that if the macro is usable in the module it will be exported to the repl irrespective of whether it was included or not. Much simpler this way too. :-)

Robert


On Saturday, 26 March 2016 20:07:29 UTC+1, Eric Bailey wrote:
Re: Arjan. Awesome, happy hacking!

Re: my message. I think what I meant was it's showing up in the docs beam chunk. Also s/Kyla/kla/

Eric




On Sat, Mar 26, 2016 at 7:29 AM -0700, "arjan" <arjan...@gmail.com> wrote:

It works like charm.
Thanks Robert.
By the way, this is my first programming experience (done very little c in university) and I'm loving it.
Thanks again.

--
You received this message because you are subscribed to the Google Groups "Lisp Flavoured Erlang" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lisp-flavoured-erlang+unsub...@googlegroups.com.
To post to this group, send email to lisp-flavoured-erlang@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages