Discussion:
[Larceny-users] ERR5RS library form question
Lynn Winebarger
2009-04-06 17:01:25 UTC
Permalink
Hello,

Is there any ready mechanism for dynamically generating the export
list of a library form from the expansion of the library form itself?
I am thinking along the lines of an internal (export <export-spec>
...) form. AFAIK, no such mechanism is supported now. It doesn't
seem like it would be that difficult to support. Would such an added
feature be acceptable to the larceny developers? Any pitfalls?

This is not an idle question. I'm writing some data-structuring
support macros that allow the user (me) to reference fields of a
record in a variable in a "C" like fashion [*]. The basic mechanisms
from the user's point of view are the data-structure definition form
(an elaborated record type definition) and a "declare" form that
causes the implicit bindings to be defined in a particular form.

My design is to generate some intermediate syntax which the user
shouldn't need to know. For example (define-data-structure ds <blah>
...) defines ds-spec (used for inheritance and declaring the structure
of fields) and declare/ds (macro-tail-called by the declare form).
The person using the defined data structure only needs to know about
"declare", not "declare/ds".

The advantage of doing this and not some internal hash table of
definitions is that the Scheme implementation will properly
disambiguate the names in the appropriate lexical context.

The disadvantage is that the user writing the definition of the data
structure has to explicitly export this support machinery. The data
structure definition should be able to (optionally) do this under the
table.

I've considered the possibility of macro-generating the library form
by walking through the code and gathering some internal "export"
forms, but the library has to actually be expanded based on imported
libraries in order for the internally exported definitions to exist.
This makes a solution that is not integrated into the library
mechanism unpleasant at best. For example, reading the library then
generating a temporary file containing the real library form
(unexpanded) with the correct export list. Yuck.

Thanks,
Lynn

[*] Am I the only Schemer who wants this facility? I'm not a fan of
destructuring/binding by pattern matching - it's too redundant for my
taste.
Derick Eddington
2009-04-07 00:41:30 UTC
Permalink
Post by Lynn Winebarger
Is there any ready mechanism for dynamically generating the export
list of a library form from the expansion of the library form itself?
I am thinking along the lines of an internal (export <export-spec>
...) form. AFAIK, no such mechanism is supported now. It doesn't
seem like it would be that difficult to support. Would such an added
feature be acceptable to the larceny developers? Any pitfalls?
JTMI, Ikarus offers it (as well as internal (import <import spec>)):

Ikarus Scheme version 0.0.4-rc1+ (revision 1757, build 2009-04-06)
Copyright (c) 2006-2008 Abdulaziz Ghuloum
Post by Lynn Winebarger
(library (def-exports)
(export def-exports)
(import (ikarus))
(define-syntax def-exports
(syntax-rules ()
((_ (name val) ...)
(begin
(define name val) ...
(export name ...))))))
Post by Lynn Winebarger
(library (A)
(export)
(import (rnrs base) (def-exports))
(def-exports (a 1) (b 2))
(define c 3)
(def-exports (d 4)))
Post by Lynn Winebarger
(import (A))
(values a b d)
1
2
4
Post by Lynn Winebarger
[*] Am I the only Schemer who wants this facility?
No. I would like it to portably exist, and I know of others who also
do. IIUC, there was discussion of this issue during the R6RS draft
period but "internal import and/or export" weren't adopted in order to
"keep things simple". You may find interesting the thread at:
http://groups.google.com/group/comp.lang.scheme/browse_thread/thread/1ba73b8267304876/7dd876d1532853d6
--
: Derick
----------------------------------------------------------------
Lynn Winebarger
2009-04-07 02:41:52 UTC
Permalink
On Mon, Apr 6, 2009 at 8:41 PM, Derick Eddington
[good info clipped]
[*]   Am I the only Schemer who wants this facility?
No.  I would like it to portably exist, and I know of others who also
do.  IIUC, there was discussion of this issue during the R6RS draft
period but "internal import and/or export" weren't adopted in order to
http://groups.google.com/group/comp.lang.scheme/browse_thread/thread/1ba73b8267304876/7dd876d1532853d6
Good reference. Aziz's "environment-symbols" and internal
import/export would simplify using Larceny's "primitives" library
syntax extension.

What I recall (and reread) of the discussion was that they wanted
people to be able process libraries with sed and such, and not need to
expand libraries to figure out dependencies.

My footnote was actually referring to the use of qualified field names
for record access (i.e. x.field1) rather than destructuring by pattern
matching or explicit procedural access/mutation. Probably not the
right forum, definitely off-topic.
Derick Eddington
2009-04-07 05:24:11 UTC
Permalink
Post by Lynn Winebarger
On Mon, Apr 6, 2009 at 8:41 PM, Derick Eddington
[good info clipped]
Post by Lynn Winebarger
[*] Am I the only Schemer who wants this facility?
No. I would like it to portably exist, and I know of others who also
do. IIUC, there was discussion of this issue during the R6RS draft
period but "internal import and/or export" weren't adopted in order to
http://groups.google.com/group/comp.lang.scheme/browse_thread/thread/1ba73b8267304876/7dd876d1532853d6
Good reference. Aziz's "environment-symbols" and internal
import/export would simplify using Larceny's "primitives" library
syntax extension.
JTMI for those who might not know, environment-symbols for Larceny can
be made as:

(define (environment-symbols env)
(map cadar (environment-bindings env)))

with environment-bindings imported from the non-standard
Larceny-specific library (rnrs eval reflection).
Post by Lynn Winebarger
My footnote was actually referring to the use of qualified field names
for record access (i.e. x.field1) rather than destructuring by pattern
matching or explicit procedural access/mutation.
Oh yeah. Sorry for misconstruing that.
--
: Derick
----------------------------------------------------------------
David Rush
2009-04-07 08:34:36 UTC
Permalink
Post by Derick Eddington
JTMI for those who might not know, environment-symbols for Larceny can
(define (environment-symbols env)
 (map cadar (environment-bindings env)))
with environment-bindings imported from the non-standard
Larceny-specific library (rnrs eval reflection).
Is there any way to get to the environment-bindings function if you're
still using Larceny in R5RS mode?

david rush
--
GPG Public key at http://cyber-rush.org/drr/gpg-public-key.txt
Marijn Schouten (hkBst)
2009-04-07 09:11:35 UTC
Permalink
JTMI
Justice through molecular information?

- --
If you cannot read my mind, then listen to what I say.

Marijn Schouten (hkBst), Gentoo Lisp project, Gentoo ML
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-{lisp,ml} on FreeNode
Derick Eddington
2009-04-07 10:03:13 UTC
Permalink
Post by Marijn Schouten (hkBst)
JTMI
Justice through molecular information?
Hahahahaha! 8-) I was going to point you to either
http://en.wiktionary.org/wiki/Appendix:Internet_slang
or
http://www.netlingo.com
but neither of them have it!

JTMI = just to mention it

I thought it was common... :-/
--
: Derick
----------------------------------------------------------------
William D Clinger
2009-04-08 00:17:10 UTC
Permalink
Post by Lynn Winebarger
Is there any ready mechanism for dynamically generating the export
list of a library form from the expansion of the library form itself?
No.
Post by Lynn Winebarger
Would such an added feature be acceptable to the larceny developers?
If the feature were part of some standard, so implementing
the feature would contribute to portability, then we would
certainly consider implementing it.
Post by Lynn Winebarger
Any pitfalls?
Well, I haven't seen the proposed syntax and don't understand
the proposed semantics.

In general, however, implementing nonstandard features tends to
degrade portability. Larceny has been a pioneer with respect to
some features, such as ERR5RS and allowing multiple libraries in
the same file, and I'm more interested in seeing progress toward
greater portability of those fairly basic features than in plowing
still further ahead by adding even more nonstandard extensions to
Larceny.

Will
William D Clinger
2009-04-08 00:21:19 UTC
Permalink
Post by David Rush
Is there any way to get to the environment-bindings function if
you're still using Larceny in R5RS mode?
Are you looking for something like this?

(define (environment-symbols env)
(append (environment-variables env)
(environment-macros env)))

Will

Continue reading on narkive:
Loading...