3 ms·
> You can consume arbitrary data using a program written in a statically typed or dynamically typed language. Really? Okay, below is something that meets the d
by kazinator 7y ago
> You can consume arbitrary data using a program written in a statically typed or dynamically typed language.
Really? Okay, below is something that meets the definition of "arbitrary data". Can some static program process it and evoke its full meaning without the programmer having to develop an ad-hoc dynamic typing system?
(defun defset-expander (env macform name params newval setform)
(with-gensyms (getter setter args gpf-pairs gpr-pairs ext-pairs
pgens rgens egens all-pairs agens nvsym)
(let* ((ap (analyze-params params))
(exp-params (car ap))
(total-syms (cadr ap))
(fp (new fun-param-parser form macform syntax exp-params))
(fixpars (append fp.req fp.(opt-syms)))
(restpar (if (symbol-package fp.rest) fp.rest))
(extsyms [keep-if symbol-package
(diff total-syms (cons restpar fixpars))])
(xsetform ^^(alet ((,',nvsym ,,newval))
,,(expand ^(symacrolet ((,newval ',nvsym))
,setform)
env))))
^(defplace (,name . ,args) body
(,getter ,setter
(tree-bind ,params ,args
(let* ((,gpf-pairs (mapcar (op (fun list) (gensym)) (list ,*fixpars)))
(,gpr-pairs (if ',restpar
(if (consp ,restpar)
(mapcar (op (fun list) (gensym)) ,restpar)
(list (list (gensym) ,restpar)))))
(,ext-pairs (mapcar (op (fun list) (gensym)) (list ,*extsyms)))
(,pgens (mapcar (fun car) ,gpf-pairs))
(,rgens (mapcar (fun car) ,gpr-pairs))
(,egens (mapcar (fun car) ,ext-pairs))
(,all-pairs (append ,gpf-pairs ,gpr-pairs ,ext-pairs))
(,agens (collect-each ((a ,args))
(let ((p (pos a ,all-pairs (fun eq) (fun cadr))))
(if p
(car (del [,all-pairs p]))
a)))))
^(alet (,*,gpf-pairs ,*,gpr-pairs ,*,ext-pairs)
,(expand ^(symacrolet (,*(zip ',fixpars
(mapcar (ret ^',@1) ,pgens))
,*(zip ',extsyms
(mapcar (ret ^',@1) ,egens))
,*(if ,gpr-pairs
(if (consp ,restpar)
^((,',restpar ',,rgens))
^((,',restpar ',(car ,rgens))))))
(macrolet ((,,getter () ^(,',',name ,',*,agens))
(,,setter (,',newval)
,',xsetform))
,body))
,env)))))))))
- yakshaving_jgt 7y agoYes. A program written in a statically-typed programming language can parse the lisp you have written above.
- kazinator 7y agoI believe that such system cannot fully process the data, as is written in that data's specification, without providing the type system that is in that specification. The requirement for dynamic typing can either come from the language, or it can be "Greenspunned", or some combination of the two. For instance, in that data we can construct objects, and we can write expressions which interrogate an object's type. Thus, that is an example of input data whose processing requires dynamic typing.
- yakshaving_jgt 7y agoI'm quite sure it's not. Statically-typed programs can recursively parse data, and they can also monadically (sequentially) parse data. The same is true of dynamically-typed programs.
- kazinator 7y agoLikewise academically speaking, statically typed programs can simulate Universal Turing Machines, QED. If the detailed requirements describing the inputs require dynamic typing, then the statically typed program has to whip up a facsimile of that dynamic typing. It's not an implementation detail; it shows up in visible, testable system behaviors. And then, there you are, with the possibility of errors that are not caught at your compile time.
- yakshaving_jgt 7y agoI don’t get it. Why are you concerned with compile time? The debate that the article is addressing is the supposed difference of capabilities between programs written with static vs dynamic types, at runtime.