Comments (23)
Properties a, b end up defined in the environment the class was defined ? Was that the intention ? I think that would cause problems unless there was an agreed standard that properties are always prefixed with a reserved symbol ":" maybe ?
from chrysalisp.
They end up in (env) at the moment...
Also, what is the significant of (env n)
where n
is positive number?
from chrysalisp.
Positive number returns the current environment and changes the number of buckets to what you ask for, default is 1. Get used when you have lots and lots of variables or are using some trick to use a parent or named environment to hold masses of assembler symbols.
Negative number mean, give me a new (env) with this (abs) this number of buckets. 0 is reserved ATM for who know what....
from chrysalisp.
(each (curry init-data-element _mye) ,properties)
That one took me a while :)
from chrysalisp.
I was thinking about making (env 0) mean a new environment that has a parent of the boot.inc shared root environment. But I havn't committed to that yet.
from chrysalisp.
for example setting up the compile-env. 307 buckets for all the assembly vars to live in.
(defun-bind within-compile-env (_)
;(within-compile-env lambda)
(defq *compile_env* (env 307) *compile_includes* (list))
(defmacro-bind defcvar (&rest b)
`(def *compile_env* ~b))
(defmacro-bind undefc (&rest b)
`(undef *compile_env* ~b))
(defmacro-bind defcfun (n a &rest b)
`(def *compile_env* ',n (lambda ,a ~b)))
(defmacro-bind defcmacro (n a &rest b)
`(def *compile_env* ',n (macro ,a ~b)))
(defmacro-bind defcfun-bind (n a &rest b)
`(def *compile_env* ',n (lambda ,a ~(bind-fun (macroexpand b)))))
(defmacro-bind defcmacro-bind (n a &rest b)
`(def *compile_env* ',n (macro ,a ~(bind-fun (macroexpand b)))))
(defun-bind include (_)
(unless (find-rev _ *compile_includes*)
(push *compile_includes* _)
(unless (defq __ (file-stream _)) (throw "No such file !" _))
(repl __ _)))
(catch (progn (setq _ (_) *compile_env* nil) _) (setq *compile_env* nil)))
from chrysalisp.
Q. Was the idea that (init-data-element) might do something fairly complex or maybe different things depending on the type of the property ? It might be seen as a bit functional overkill if it just def's some nils...
from chrysalisp.
Everything is fluid so it could be imbued in the macro technically. I am learning macros, quoting, etc. etc. etc. as I go. Here is the latest that I've started to work in subclasses (which breaks but...):
(def: '(clz super) (env))
(defmacro first (el)
; First element from sequence
`(elem 0 ,el))
(defmacro second (el)
; Second element from sequence
`(elem 1 ,el))
(defmacro sfind (ss slst)
`(some (lambda (_tvar)
(if (eql ,ss _tvar) _)) ,slst))
(defmacro union (seq1 seq2)
`(reduce (lambda (acc el)
(if (find el acc)
acc
(push acc el))) ,seq2 ,seq1))
(defun init-data-element (environment data-element)
(def environment data-element nil))
(defun clz-name (cclz) (elem 0 cclz))
(defun clz-super (cclz) (elem 1 cclz))
(defun clz-properties (cclz) (elem 2 cclz))
(defmacro class (name properties &optional super_clz)
(defq
_sname (str name)
_new (sym (str name ".new"))
_init (sym (str name ".init"))
_del (sym (str name ".del"))
_get (sym (str name ".get"))
_set (sym (str name ".set")))
`(progn
(if ,super_clz
(setq properties
(union
,properties
(clz-properties (eval ,super_clz (env))))))
(def: ,properties (env)) ; Make symbbols available
(defq ,name ; Meta data contains class stuff
(list
(list clz ,_sname) ; My name
(list super ,super_clz) ; My parent
(cat ,properties) ; My properties
(list) ; Function names?
(list))) ; Unknown usage yet
(defun ,_init (self &rest args)
(print "Init " ,_sname " with " self)
self)
(defun ,_new ()
(defq _mye (env -1))
(each (curry init-data-element _mye) ,properties)
(,_init _mye))
(defun ,_get (self data-element)
(eval data-element self))
(defun ,_set (self data-element val)
(set self data-element val))
(defun ,_del (self) (print ,_sname "Instance delete for " self))
))
(class object '(a b))
(defq o1 (object.new))
(object.get o1 a)
(object.set o1 a "value")
However; this is failing:
(class subclz '(e f) object)
Error: (lambda ([arg ...]) body) not_a_lambda ! < clz > File: stdin(3)
from chrysalisp.
(defmacro union (seq1 seq2)
`(reduce (lambda (acc el)
(if (find el acc)
acc
(push acc el))) ,seq2 ,seq1))
That looks very much like the built in (merge) in boot.inc ?
If you look in class/list/lisp.vp, line 70.
Not exactly a boot.inc defined function, but a built in of the list VP class.
from chrysalisp.
Can't look now but I tested merge
in REPL and it may conjoin versus de-dupe. I'll check again later...
from chrysalisp.
(setq properties...
How does that work ? properties is a list of symbols ?....
Do you mean to do a (bind ...) ?
No, hold on that's not ,properties.
from chrysalisp.
My intent was to update the properties argument with the union of the subclass with the class being created properties.
from chrysalisp.
(setq properties...
But where is 'properties' going to already exist ? That (progn) is what get's emited as a result of the macro expansion ? And setq will search for a variable called properties to set, and I don't see where it ever gets defined ?
properties exists in the context of the macro expansion, but at runtime when the (progn) is executed there is no 'properties' symbol in existence.
from chrysalisp.
Properties are contained in the class's meta data as defined by (defq ,name ...)
from chrysalisp.
Yes, but I don't see where 'properties' exist in the environment where the `(progn...) runs ? Am I just missing something ? When you define a subclass are you suposed to do it inside the parent classes environment so that 'properties' does exist ?
from chrysalisp.
It's an argument to the macro running.
from chrysalisp.
And we are back to, but that `(progn...) does not run in the environment of that class macro... :)
from chrysalisp.
Do you just want the:
(if ,super_clz
(setq properties
(union
,properties
(clz-properties (eval ,super_clz (env))))))
To be before the `(progn..) ?
And not be using ,properties ? So:
(if super_clz
(setq properties
(union
properties
(clz-properties (eval super_clz (env))))))
But then I'm concerned about that (env), that would be the (env) of the class macro during (read) time ?
from chrysalisp.
Lisp like Forth has this very different and very confusing TBH, compile (read) environment and the actual programmes eventual runtime environment.
Everything in a macro is running in the (read) environment. It's creating and substituting sections of AST for the eventual code that gets evaluated at runtime. But any variables and environment that existed during macro expansion and (read) is long gone...
from chrysalisp.
Woof
from chrysalisp.
Getting a bit better at understanding the whole macro/environment abyss. I've broken up the class creation from the properties settings. Still haven't figured out at what point to (def: ...)
the properties yet:
(defq main_env env)
(def: '(clz super properties) (main_env))
(defun clz-name (cclz) (elem 1 (elem 0 cclz)))
(defun clz-super (cclz) (elem 1 (elem 1 cclz)))
(defun clz-properties (cclz) (elem 1 (elem 2 cclz)))
(defmacro class (name &optional super_clz)
(defq
_sname (str name)
_new (sym (str name ".new"))
_init (sym (str name ".init"))
_del (sym (str name ".del"))
_get (sym (str name ".get"))
_set (sym (str name ".set")))
`(progn
(defq ,name ; Meta data contains class stuff
(list
(list clz ,_sname) ; My name
(list super ,super_clz) ; My parent
(list properties (list)) ; My properties
(list) ; Function names?
(list))) ; Unknown usage yet
(defun ,_init (self &rest args)
(print "Init " ,_sname " with " self)
self)
(defun ,_new ()
(defq _mye (main_env -1))
(each (curry init-data-element _mye) (clz-properties ,name))
(,_init _mye))
(defun ,_get (self data-element)
(eval data-element self))
(defun ,_set (self data-element val)
(set self data-element val))
(defun ,_del (self) (print ,_sname "Instance delete for " self))
))
(defmacro class-properties (clz plist)
`(let ((props (gensym)))
(defq props (clz-properties ,clz))
(each (lambda (e) (push props e)) ,plist)))
; (class object)
; (class-properties object '(a b))
; (defq o1 (object.new))
from chrysalisp.
Class-properties
Are you really meaning to generate a symbol at runtime ?
Just checking as (gensym) normally gets used in the macro to plant some symbol that just exists at runtime.
Itβs quite somthing to want to generate a new symbol at runtime! But then Iβm getting old and so Iβm maybe a couple of environments short of the modern way of thinking ;)
from chrysalisp.
To enable the user to do a (class.set obj field value)
the field
can be symbols pre-populated in the environment.
Using the example at the bottom of the new post above, I would be able to do a:
(object.set o1 a "value")
from chrysalisp.
Related Issues (20)
- Transition Log Service to new IPC and data exchangers HOT 1
- Fix yaml string quote compounding
- Display scaling options? HOT 5
- src/main.cpp:37:11: fatal error: 'SDL.h' file not found HOT 5
- Package manager needed HOT 3
- @Chris HOT 16
- Containers woven in to foundations HOT 1
- Interprocess communication port needed HOT 4
- WYSIWYG interface builder HOT 6
- A browser for ChrysaLisp pages. HOT 10
- WebDriver compatible functional UI clicking test automation HOT 1
- reload definitions in lisp HOT 3
- error while compiling HOT 3
- error HOT 1
- rather a request: RISCV would be great HOT 10
- SDL2 dep for building on Macs - tweaks needed? HOT 9
- Bootstrapping ChrysaLisp on ChrysaLisp? HOT 10
- README feedback HOT 5
- Transparent windows HOT 1
- Can it run Doom? HOT 1
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 chrysalisp.