Git Product home page Git Product logo

Comments (23)

vygr avatar vygr commented on May 5, 2024

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.

FrankC01 avatar FrankC01 commented on May 5, 2024

They end up in (env) at the moment...

Also, what is the significant of (env n) where n is positive number?

from chrysalisp.

vygr avatar vygr commented on May 5, 2024

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.

vygr avatar vygr commented on May 5, 2024

(each (curry init-data-element _mye) ,properties)

That one took me a while :)

from chrysalisp.

vygr avatar vygr commented on May 5, 2024

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.

vygr avatar vygr commented on May 5, 2024

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.

vygr avatar vygr commented on May 5, 2024

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.

FrankC01 avatar FrankC01 commented on May 5, 2024

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.

vygr avatar vygr commented on May 5, 2024
(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.

FrankC01 avatar FrankC01 commented on May 5, 2024

Can't look now but I tested merge in REPL and it may conjoin versus de-dupe. I'll check again later...

from chrysalisp.

vygr avatar vygr commented on May 5, 2024

(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.

FrankC01 avatar FrankC01 commented on May 5, 2024

My intent was to update the properties argument with the union of the subclass with the class being created properties.

from chrysalisp.

vygr avatar vygr commented on May 5, 2024

(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.

FrankC01 avatar FrankC01 commented on May 5, 2024

Properties are contained in the class's meta data as defined by (defq ,name ...)

from chrysalisp.

vygr avatar vygr commented on May 5, 2024

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.

FrankC01 avatar FrankC01 commented on May 5, 2024

It's an argument to the macro running.

from chrysalisp.

vygr avatar vygr commented on May 5, 2024

And we are back to, but that `(progn...) does not run in the environment of that class macro... :)

from chrysalisp.

vygr avatar vygr commented on May 5, 2024

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.

vygr avatar vygr commented on May 5, 2024

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.

FrankC01 avatar FrankC01 commented on May 5, 2024

Woof

from chrysalisp.

FrankC01 avatar FrankC01 commented on May 5, 2024

@vygr

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.

vygr avatar vygr commented on May 5, 2024

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.

FrankC01 avatar FrankC01 commented on May 5, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.