Comments (6)
I think maybe the side-effecty stuff at the top of compile-toplevel-define-type-form
that appears to be registering the tycon
and it's constructors needs to be pushed down into the macro expansion, possibly within an eval-when
?
Proof-of-concept PR coming soon (hopefully)...
from deprecated-coalton-prototype.
Thinking about this a bit more, perhaps things are not so simple as I had hoped (they never are!).
There seem to be at least three competing concerns here:
- Definitions inside a single
coalton-toplevel
form need to be visible to each other at macro-expansion time. - Definitions should also be visible at
:load-toplevel
time, so that loading a precompiled FASL does the right thing. - Definitions should be re-definable, ideally without gratuitous warnings in the common case of compiling, then loading a file.
The corollary to (3) is that the definitions should only be registered in the global environment once, probably inside the macro form and possibly wrapped in an (eval-when (:compile-toplevel :load-toplevel :execute) ...)
. (I suspect the :compile-toplevel
is not needed which means the eval-when
is not needed, but, as usual, staring at the hyperspec section for Processing Toplevel Forms has left me less than certain...).
But pushing the tycon and ctor registrations down into the macro form means that the macro expander needs some other provision to know about in-process definitions. The current implementation already tracks an extra-tycons
parameter for this purpose, and parse-type-expression
is smart enough to lookup stuff in extra-tycons
before trying the "global environment." Perhaps similar provisions could be made for ctors and the like. So far I have been ignoring other toplevel definition forms like define
and declare
, which may need similar treatment (haven't looked yet).
Maybe instead of just extra-tycons
any of the process-toplevel-*
functions (and whatever functions they call) could get passed some kind of environment object that tracks all type/ctor/value definitions, similar to the &environment
defmacro parameter.
tl;dr - Not quite as simple as I had hoped. I should probably read and understand the coalton source (and maybe the MACROEXPAND-ALL chapter of this Dick Waters paper) before proceeding further :). I have other stuff I want to work on first, but will circle back to this eventually (famous last words).
from deprecated-coalton-prototype.
This is a good thing to pick up on. I've felt uneasy about the compile-time side effects Coalton does. There needs to be a better way to manage it all.
from deprecated-coalton-prototype.
Probably what needs to happen is side effects need to happen at macroexpansion time, but they also need to be put in the macroexpansion as well so the FASL loader catches them.
It seems to be "working" when I do that, e.g.
diff --git a/src/toplevel-define-type.lisp b/src/toplevel-define-type.lisp
index b016280..9e56c55 100644
--- a/src/toplevel-define-type.lisp
+++ b/src/toplevel-define-type.lisp
@@ -101,6 +101,14 @@ where
;; TODO: Structs? Vectors? Classes? This should be thought
;; about. Let's start with classes.
`(progn
+ ;; Make sure database side effects are maintained.
+ (eval-when (:compile-toplevel :load-toplevel :execute)
+ (setf (find-tycon ',tycon-name) ,tycon)
+ ,@(loop :for (_ name ty) :in ctors
+ :collect `(unless (var-knownp ',name)
+ (forward-declare-variable ',name))
+ :collect `(setf (var-declared-type ',name) ,ty)))
+
;; Define types. Create the superclass.
;;
;; TODO: handle special case of 1 ctor.
from deprecated-coalton-prototype.
Note: PR in progress #14
from deprecated-coalton-prototype.
The diff in #14 looks similar to what I did in #12. I'm struggling to remember now why I abandoned that PR. Can't remember if I stumbled on a bug or if I was just vaguely unsatisfied with it.
from deprecated-coalton-prototype.
Related Issues (18)
- Expand macros in COALTON-TOPLEVEL
- Tuple support HOT 1
- Write `type=` function
- have a separate DEFINE-MACRO within Coalton
- Coalton thinks (-> (Liszt t) t) is a binary function HOT 4
- build essential functions into standard library
- add AND, OR
- Typeclasses HOT 1
- Allow syntactic sugar (fn a -> b -> ... -> z)
- ensure DEFINE-TYPE defined constructors are lexical HOT 2
- figure out printing, especially lists.
- Start unit test suite
- Improve Coalton <-> Lisp bridge
- Check declared type against inferred type
- Vastly improve error message experience
- Implement more general pattern matching facility HOT 1
- Bad error message when defining a constructor & type of same name
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deprecated-coalton-prototype.