unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Guix records
@ 2021-02-05 16:51 Olivier Dion via General Guile related discussions
  2021-02-09 23:14 ` Taylan Kammer
  2021-02-09 23:32 ` Aleix Conchillo Flaqué
  0 siblings, 2 replies; 8+ messages in thread
From: Olivier Dion via General Guile related discussions @ 2021-02-05 16:51 UTC (permalink / raw)
  To: guile-user

Hello,

In the module (guix records), there's some very nice syntax rule
`define-record-type*` that allows very powerfull declarative style of
records.  For example:
----------------------------------------------------------------------
(employee
  (age  30)
  (name "Foo")
  (profession "Teacher"))
---------------------------------------------------------------------- 

I would like to use this feature in my software.  However, I don't want
to have Guix as a dependency only for that.  For now, I've copied the
content of (guix records) into (my-software records).  But this put
burden of maitenance into my hands.

Thus, I'm looking for an alternative, perhaps there's a Guile library
(other than Guix' module) or a SRFI that offers similar feature?

-- 
Olivier Dion
PolyMtl



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guix records
  2021-02-05 16:51 Guix records Olivier Dion via General Guile related discussions
@ 2021-02-09 23:14 ` Taylan Kammer
  2021-02-10  1:02   ` Dr. Arne Babenhauserheide
  2021-02-09 23:32 ` Aleix Conchillo Flaqué
  1 sibling, 1 reply; 8+ messages in thread
From: Taylan Kammer @ 2021-02-09 23:14 UTC (permalink / raw)
  To: Olivier Dion, guile-user

On 05.02.2021 17:51, Olivier Dion via General Guile related discussions 
wrote:
> Hello,
> 
> In the module (guix records), there's some very nice syntax rule
> `define-record-type*` that allows very powerfull declarative style of
> records.  For example:
> ----------------------------------------------------------------------
> (employee
>    (age  30)
>    (name "Foo")
>    (profession "Teacher"))
> ----------------------------------------------------------------------
> 
> I would like to use this feature in my software.  However, I don't want
> to have Guix as a dependency only for that.  For now, I've copied the
> content of (guix records) into (my-software records).  But this put
> burden of maitenance into my hands.
> 
> Thus, I'm looking for an alternative, perhaps there's a Guile library
> (other than Guix' module) or a SRFI that offers similar feature?
> 

The most feature-rich record system supported by Guile is probably the 
R6RS record system, which is available through the modules:

   (rnrs records syntactic (6))
   (rnrs records procedural (6))
   (rnrs records inspection (6))

However, it doesn't allow a definition style like in your example, where 
you explicitly name the fields that you're assigning values to during 
instance creation.

It does, however, implicitly define getters (and setters for mutable 
fields).

The Guile documentation is brief.  You might want to read the R6RS spec 
or search for another guide for detailed explanations and examples of 
how to use the R6RS record system, if it sounds interesting.

Note that it's quite dissimilar to the SRFI-9 system, and some aspects 
of it are rather complex, which is why many people don't like it.  To be 
honest I find some of those complex features quite ingenious on paper, 
though I couldn't say how often they would prove to be useful in practice.

Here's a super brief example usage of R6RS records, demonstrating that 
field accessors are defined implicitly, but constructors still use an 
unnamed sequence of arguments to assign fields:

   (import (rnrs records syntactic (6)))  ; must use 'import' for R6RS

   (define-record-type (cat make-cat cat?) (fields name age color))

   (define garfield (make-cat "Garfield" 42 'orange))

   (cat-color garfield)  ;=>  orange



Then there is SRFI-99 which could be seen as an update to SRFI-9, but 
last I checked it's not in Guile yet.  It also doesn't really feature 
the declarative style like in your example.



- Taylan



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guix records
  2021-02-05 16:51 Guix records Olivier Dion via General Guile related discussions
  2021-02-09 23:14 ` Taylan Kammer
@ 2021-02-09 23:32 ` Aleix Conchillo Flaqué
  2021-02-10  0:28   ` Olivier Dion via General Guile related discussions
  1 sibling, 1 reply; 8+ messages in thread
From: Aleix Conchillo Flaqué @ 2021-02-09 23:32 UTC (permalink / raw)
  To: Olivier Dion; +Cc: guile-user

Hi Olivier,

Unfortunately I don't have an answer, and actually I didn't even know this
existed, but I'd love to see a library for it. I added something similar
(in terms of syntax) to guile-json (define-json-type) and I'm happy to see
that it seems I was not doing something very stupid. For this specific
record it would be something like:

(define-json-type <employee>
  (age)
  (name)
  (profession))

Which will define a constructor and getters (no setters). However, to
create a new record you have to use the constructor (which is not very
convenient) or use an alist and then use (scm->employee). But it would be
great if one could do:

(employee->json
   (employee
      (age  30)
      (name "Foo")
      (profession "Teacher")))

instead of:

(employee->json
   (scm->employee
      '((age . 30)
        (name . "Foo")
        (profession . "Teacher"))))

It would be fantastic to combine (guix records) and guile-json somehow, but
I'm not sure how.

Sorry I couldn't provide any useful insight.

Best,

Aleix

On Fri, Feb 5, 2021 at 9:24 AM Olivier Dion via General Guile related
discussions <guile-user@gnu.org> wrote:

> Hello,
>
> In the module (guix records), there's some very nice syntax rule
> `define-record-type*` that allows very powerfull declarative style of
> records.  For example:
> ----------------------------------------------------------------------
> (employee
>   (age  30)
>   (name "Foo")
>   (profession "Teacher"))
> ----------------------------------------------------------------------
>
> I would like to use this feature in my software.  However, I don't want
> to have Guix as a dependency only for that.  For now, I've copied the
> content of (guix records) into (my-software records).  But this put
> burden of maitenance into my hands.
>
> Thus, I'm looking for an alternative, perhaps there's a Guile library
> (other than Guix' module) or a SRFI that offers similar feature?
>
> --
> Olivier Dion
> PolyMtl
>
>


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guix records
  2021-02-09 23:32 ` Aleix Conchillo Flaqué
@ 2021-02-10  0:28   ` Olivier Dion via General Guile related discussions
  2021-02-10 21:11     ` Aleix Conchillo Flaqué
  0 siblings, 1 reply; 8+ messages in thread
From: Olivier Dion via General Guile related discussions @ 2021-02-10  0:28 UTC (permalink / raw)
  To: Aleix Conchillo Flaqué; +Cc: guile-user

On Tue, 09 Feb 2021, Aleix Conchillo Flaqué <aconchillo@gmail.com> wrote:
> Hi Olivier,
>
> Unfortunately I don't have an answer, and actually I didn't even know this
> existed, but I'd love to see a library for it. I added something similar
> (in terms of syntax) to guile-json (define-json-type) and I'm happy to see
> that it seems I was not doing something very stupid. For this specific
> record it would be something like:
>
> (define-json-type <employee>
>   (age)
>   (name)
>   (profession))
>
> Which will define a constructor and getters (no setters). However, to
> create a new record you have to use the constructor (which is not very
> convenient) or use an alist and then use (scm->employee). But it would be
> great if one could do:

Is (scm->employee) something (define-json-type) offers?  Just having
that would be great.  I would be more tolerant to have guile-json as a
dependency, since it's most likely lighter than Guix, probably already
installed on the user system and it might me useful for users that are
allergic to parentheses for configuration.

>
> (employee->json
>    (employee
>       (age  30)
>       (name "Foo")
>       (profession "Teacher")))
>
> instead of:
>
> (employee->json
>    (scm->employee
>       '((age . 30)
>         (name . "Foo")
>         (profession . "Teacher"))))
>
> It would be fantastic to combine (guix records) and guile-json somehow, but
> I'm not sure how.

If guile-json' license is compatible with Guix' license, I don't see any
problem with taking the code from Guix and adapting it for guile-json.

>
> Sorry I couldn't provide any useful insight.
>
> Best,
>
> Aleix
>
> On Fri, Feb 5, 2021 at 9:24 AM Olivier Dion via General Guile related
> discussions <guile-user@gnu.org> wrote:
>
>> Hello,
>>
>> In the module (guix records), there's some very nice syntax rule
>> `define-record-type*` that allows very powerfull declarative style of
>> records.  For example:
>> ----------------------------------------------------------------------
>> (employee
>>   (age  30)
>>   (name "Foo")
>>   (profession "Teacher"))
>> ----------------------------------------------------------------------
>>
>> I would like to use this feature in my software.  However, I don't want
>> to have Guix as a dependency only for that.  For now, I've copied the
>> content of (guix records) into (my-software records).  But this put
>> burden of maitenance into my hands.
>>
>> Thus, I'm looking for an alternative, perhaps there's a Guile library
>> (other than Guix' module) or a SRFI that offers similar feature?
>>
>> --
>> Olivier Dion
>> PolyMtl
>>
>>
-- 
Olivier Dion
PolyMtl



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guix records
  2021-02-09 23:14 ` Taylan Kammer
@ 2021-02-10  1:02   ` Dr. Arne Babenhauserheide
  2021-02-10  5:37     ` Taylan Kammer
  0 siblings, 1 reply; 8+ messages in thread
From: Dr. Arne Babenhauserheide @ 2021-02-10  1:02 UTC (permalink / raw)
  To: Taylan Kammer; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1183 bytes --]


Taylan Kammer <taylan.kammer@gmail.com> writes:
> The most feature-rich record system supported by Guile is probably the
> R6RS record system, which is available through the modules:
>
>   (rnrs records syntactic (6))
>   (rnrs records procedural (6))
>   (rnrs records inspection (6))
> Here's a super brief example usage of R6RS records, demonstrating that
> field accessors are defined implicitly, but constructors still use an 
> unnamed sequence of arguments to assign fields:
>
>   (import (rnrs records syntactic (6)))  ; must use 'import' for R6RS
>
>   (define-record-type (cat make-cat cat?) (fields name age color))
>
>   (define garfield (make-cat "Garfield" 42 'orange))
>
>   (cat-color garfield)  ;=>  orange

I did not know about that shorthand — thank you!

I always did this:

(import (srfi srfi-9)) ; define-record-type
(define-record-type <cat>
  (make-cat name age color)
  cat?
  (name cat-name) (age cat-age) (color cat-color))

Compared to that the syntactic form you showed is much nicer.

Is there a difference in efficiency or such?

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guix records
  2021-02-10  1:02   ` Dr. Arne Babenhauserheide
@ 2021-02-10  5:37     ` Taylan Kammer
  2021-02-10  8:38       ` Dr. Arne Babenhauserheide
  0 siblings, 1 reply; 8+ messages in thread
From: Taylan Kammer @ 2021-02-10  5:37 UTC (permalink / raw)
  To: Dr. Arne Babenhauserheide; +Cc: guile-user

On 10.02.2021 02:02, Dr. Arne Babenhauserheide wrote:
> 
> Taylan Kammer <taylan.kammer@gmail.com> writes:
>> The most feature-rich record system supported by Guile is probably the
>> R6RS record system, which is available through the modules:
>>
>>    (rnrs records syntactic (6))
>>    (rnrs records procedural (6))
>>    (rnrs records inspection (6))
>> Here's a super brief example usage of R6RS records, demonstrating that
>> field accessors are defined implicitly, but constructors still use an
>> unnamed sequence of arguments to assign fields:
>>
>>    (import (rnrs records syntactic (6)))  ; must use 'import' for R6RS
>>
>>    (define-record-type (cat make-cat cat?) (fields name age color))
>>
>>    (define garfield (make-cat "Garfield" 42 'orange))
>>
>>    (cat-color garfield)  ;=>  orange
> 
> I did not know about that shorthand — thank you!
> 
> I always did this:
> 
> (import (srfi srfi-9)) ; define-record-type
> (define-record-type <cat>
>    (make-cat name age color)
>    cat?
>    (name cat-name) (age cat-age) (color cat-color))
> 
> Compared to that the syntactic form you showed is much nicer.

I actually prefer the conceptual simplicity and explicit nature of 
SRFI-9 to be honest, but yeah, it can be very verbose.

> Is there a difference in efficiency or such?

Theoretically there shouldn't be, since the implicit defining of the 
accessors happens at compile time.  However, pre Guile 3.0, the R6RS 
record system was implemented completely independently from the SRFI-9 
implementation, so the two could have various differences in performance.

According to the 3.0 release notes, R6RS and SRFI-9 now both use a 
unified core record system under the hood and should therefore have 
equivalent performance characteristics I suppose.

> Best wishes,
> Arne
> 

- Taylan



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guix records
  2021-02-10  5:37     ` Taylan Kammer
@ 2021-02-10  8:38       ` Dr. Arne Babenhauserheide
  0 siblings, 0 replies; 8+ messages in thread
From: Dr. Arne Babenhauserheide @ 2021-02-10  8:38 UTC (permalink / raw)
  To: Taylan Kammer; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1143 bytes --]


Taylan Kammer <taylan.kammer@gmail.com> writes:

>>>    (import (rnrs records syntactic (6)))
>>>    (define-record-type (cat make-cat cat?) (fields name age color))
>> I did not know about that shorthand — thank you!
>> I always did this:
>> (import (srfi srfi-9))
>> (define-record-type <cat>
>>    (make-cat name age color)
>>    cat?
>>    (name cat-name) (age cat-age) (color cat-color))
>> Compared to that the syntactic form you showed is much nicer.
>
> I actually prefer the conceptual simplicity and explicit nature of
> SRFI-9 to be honest, but yeah, it can be very verbose.

I’ve used records a bit, and the additional overhead is annoying.
On the other hand I like it that there is an explicit entry in the file,
so I don’t get magic variables that my text editor cannot find without
executing the code.

> According to the 3.0 release notes, R6RS and SRFI-9 now both use a
> unified core record system under the hood and should therefore have 
> equivalent performance characteristics I suppose.

Thank you!

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 1125 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Guix records
  2021-02-10  0:28   ` Olivier Dion via General Guile related discussions
@ 2021-02-10 21:11     ` Aleix Conchillo Flaqué
  0 siblings, 0 replies; 8+ messages in thread
From: Aleix Conchillo Flaqué @ 2021-02-10 21:11 UTC (permalink / raw)
  To: Olivier Dion; +Cc: guile-user

On Tue, Feb 9, 2021 at 4:28 PM Olivier Dion <olivier.dion@polymtl.ca> wrote:

> On Tue, 09 Feb 2021, Aleix Conchillo Flaqué <aconchillo@gmail.com> wrote:
> > Hi Olivier,
> >
> > Unfortunately I don't have an answer, and actually I didn't even know
> this
> > existed, but I'd love to see a library for it. I added something similar
> > (in terms of syntax) to guile-json (define-json-type) and I'm happy to
> see
> > that it seems I was not doing something very stupid. For this specific
> > record it would be something like:
> >
> > (define-json-type <employee>
> >   (age)
> >   (name)
> >   (profession))
> >
> > Which will define a constructor and getters (no setters). However, to
> > create a new record you have to use the constructor (which is not very
> > convenient) or use an alist and then use (scm->employee). But it would be
> > great if one could do:
>
> Is (scm->employee) something (define-json-type) offers?  Just having
> that would be great.  I would be more tolerant to have guile-json as a
> dependency, since it's most likely lighter than Guix, probably already
> installed on the user system and it might me useful for users that are
> allergic to parentheses for configuration.
>
>
Yes, it is. Actually (scm->employee) is something that
(define-json-mapping) offers (also in guile-json). (define-json-mapping)
was originally copied from (guix json) which no longer exists in Guix, they
use guile-json instead.

Then (define-json-type) is based on (define-json-mapping), but yes all of
this is available in guile-json.


> >
> > It would be fantastic to combine (guix records) and guile-json somehow,
> but
> > I'm not sure how.
>
> If guile-json' license is compatible with Guix' license, I don't see any
> problem with taking the code from Guix and adapting it for guile-json.
>
>
Yes, they both are GPLv3. I was referring about how to actually do it
without breaking anything.
Aleix


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-02-10 21:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05 16:51 Guix records Olivier Dion via General Guile related discussions
2021-02-09 23:14 ` Taylan Kammer
2021-02-10  1:02   ` Dr. Arne Babenhauserheide
2021-02-10  5:37     ` Taylan Kammer
2021-02-10  8:38       ` Dr. Arne Babenhauserheide
2021-02-09 23:32 ` Aleix Conchillo Flaqué
2021-02-10  0:28   ` Olivier Dion via General Guile related discussions
2021-02-10 21:11     ` Aleix Conchillo Flaqué

unofficial mirror of guile-user@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guile-user/0 guile-user/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guile-user guile-user/ https://yhetil.org/guile-user \
		guile-user@gnu.org
	public-inbox-index guile-user

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.lisp.guile.user
	nntp://news.gmane.io/gmane.lisp.guile.user


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git