News for hackers. Stuff that matters.
Re:Dynamic type systems are not inherently more open by kazinator on Monday January 20, 2020 @12:32AM (#22096562)
> 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)))))))))
Re:Dynamic type systems are not inherently more open by yakshaving_jgt on Monday January 20, 2020 @02:54AM (#22097181)
Yes. A program written in a statically-typed programming language can parse the lisp you have written above.
Re:Dynamic type systems are not inherently more open by kazinator on Monday January 20, 2020 @11:17AM (#22099843)
I 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.

Re:Dynamic type systems are not inherently more open by yakshaving_jgt on Monday January 20, 2020 @11:55AM (#22100144)
I'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.
Re:Dynamic type systems are not inherently more open by kazinator on Monday January 20, 2020 @01:26PM (#22100936)
Likewise 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.

Re:Dynamic type systems are not inherently more open by yakshaving_jgt on Monday January 20, 2020 @01:56PM (#22101203)
I 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.

Re:Dynamic type systems are not inherently more open by kazinator on Monday January 20, 2020 @03:18PM (#22101787)
The situation is not written entirely with static types if the run-time processing requires the expression of dynamic typing. That's based on some actual dynamic typing from the language, or else some ad hoc dynamic types cobbed together in the program itself.
Re:Dynamic type systems are not inherently more open by sethev on Monday January 20, 2020 @05:10PM (#22102498)
You picked a strange example since so many Lisps were implemented in statically typed languages.

Here's one in C (less than 200 lines): https://carld.github.io/2017/06/20/lisp-in-less-than-200-lin...

Here's one in Haskell: https://www.defmacro.org/ramblings/lisp-in-haskell.html

Re:Dynamic type systems are not inherently more open by kazinator on Monday January 20, 2020 @05:29PM (#22102606)
That first one looks dynamically typed through a List * type, and tags put into pointers. That algebraic type in Haskell also looks dynamic: an Expr can be any one of four things.
Re:Dynamic type systems are not inherently more open by sethev on Monday January 20, 2020 @06:32PM (#22102961)
This supports the case the article was making. Clearly the type system in Haskell doesn't prevent it from handling arbitrary data - it's hard to imagine a program more open to change in the input data than a Lisp interpreter.

You seem to have a set of rules that you think code in a statically typed language has to follow in addition to the type constraints in order for you to consider it sufficiently 'typed'.

Re:Dynamic type systems are not inherently more open by kazinator on Monday January 20, 2020 @07:59PM (#22103399)
Well, just one rule: if we are looking at type tags at run-time, it's dynamic typing! Whether that be things put into C pointers, or integer fields discriminating unions, or algebraic sum types with pattern matching.

If someone writes Haskell applications by defining an Expr type that is a sum of several dozen things, and then makes al their function arguments and return values of type Expr, is that still bona fide static typing?