Should struct have an #:extra-id-name ?

71 views
Skip to first unread message

Jens Axel Søgaard

unread,
Apr 2, 2016, 4:26:44 PM4/2/16
to d...@racket-lang.org
Consider this snippet from scribble/html/xml

(provide make-element)
(struct element (tag attrs body [cache #:auto #:mutable])
  #:constructor-name make-element
  #:transparent #:omit-define-syntaxes #:auto-value #f
  #:property prop:procedure
  (lambda (e)
    (unless (element-cache e) (set-element-cache! e (element->output e)))
    (element-cache e)))

(provide element)
(define (element tag . args)
  (define-values [attrs body] (attributes+body args))
  (make-element tag attrs body))

I would like to provide the structure definition, but simply adding (provide (struct-out element)) does not work, since  element  is not bound to the structure id.

An #:extra-id-name option for struct could solve this.

Is there another way to provide the struct element without renaming the element function?

/Jens Axel





--
--
Jens Axel Søgaard

Jens Axel Søgaard

unread,
Apr 10, 2016, 12:33:54 PM4/10/16
to d...@racket-lang.org
Ping.

Matthew Flatt

unread,
Apr 11, 2016, 11:10:46 AM4/11/16
to Jens Axel Søgaard, d...@racket-lang.org
I can't think of a good alternative, and a way to provide a name for
the static info sounds fine to me.
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-dev+...@googlegroups.com.
> To post to this group, send email to racke...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-dev/CABefVgwdePmoo556iL_%2BVj0d5_dpFux
> Z-WR_bsP43nqVRhy_DQ%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Jens Axel Søgaard

unread,
Apr 14, 2016, 10:27:57 AM4/14/16
to Matthew Flatt, d...@racket-lang.org
For the archives:


I have added #:extra-id-name and tried to mimic the coding style.

In    (struct foo (bar) #:extra-id-name baz)
the struct information in the compile time variable foo
and baz will be shared.

In    (struct foo (bar) #:extra-id-name baz
                                 #:omit-define-syntaxes)
the information will only be stored in baz.

Example:

#lang racket
(provide (struct-out baz))

(struct foo (bar)
  #:transparent
  #:extra-id-name baz
  #:omit-define-syntaxes
  #:omit-define-values
  #:constructor-name Foo)

(define (foo x)
  (Foo 42))

(foo 42)

produces a struct  value containing 42.

Does the approach look reasonable?

/Jens Axel


Reply all
Reply to author
Forward
0 new messages