Re: static typing
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Mon, 07 Aug 2006 13:45:03 +0200
Nathan Baum <nathan_baum@xxxxxxxxxxxxxx> writes:
For example, if you have a tree of nodes with a label and a variableThis doesn't completely solve the problem. There's no standard way to
number of children, you should use: LEAFP, MAKE-NODE, NODE-LABEL and
NODE-CHILDREN. You can still implement your nodes with lists:
(defun LEAFP (object) (not (consp object)))
(defun MAKE-NODE (label &rest children) (cons label children))
(defun NODE-LABEL (node) (first node))
(defun NODE-CHILDREN (node) (rest node))
[...]
process a form/file checking for type errors, which is really the
point. I can still type
> (defun bad ()
(node-label 12))
which is Obviously Wrong.
How so? I've not specified anything about the type of the labels.
(The type of children is infered from &rest children : it's LIST.)
It would be useful to do
> (typecheck bad)
*** argument to NODE-LABEL is FIXNUM, expecting NODE.
Well, perhaps you're expecing SYMBOL. Just say so:
(defun MAKE-NODE (label &rest children)
(declare (type symbol label))
(cons label children))
As for type inference, what more do you want than:
* (defun k (x) (car (+ 1 x)))
; in: LAMBDA NIL
; (CAR (+ 1 X))
;
; caught WARNING:
; Asserted type LIST conflicts with derived type (VALUES NUMBER &OPTIONAL).
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
Sure, but that isn't a requirement of the standard.
So what? It's not a standard requirement either! If you have this
requirement, choose an implementation that does it, like SBCL.
Way back when I
tested Corman and LispWorks, and I didn't notice them doing any type
inference.
Nonetheless, all the implementations I know do type checking (at
run-time at least) unless you compiled with (declaim (optimize (speed
3) (safety 0))).
Of course, the hypothetical linting library could perform this kind of
type checking, and attach explicit type annotations. This kind of
functionality doesn't actually need to be 'in the language', but it
would be useful functionality to have access to, I think.
You may want to try ACL2. http://www.cs.utexas.edu/users/moore/acl2/
--
__Pascal Bourguignon__ http://www.informatimago.com/
READ THIS BEFORE OPENING PACKAGE: According to certain suggested
versions of the Grand Unified Theory, the primary particles
constituting this product may decay to nothingness within the next
four hundred million years.
.
- Follow-Ups:
- Re: static typing
- From: Nathan Baum
- Re: static typing
- References:
- Re: static typing
- From: Nathan Baum
- Re: static typing
- Prev by Date: Re: Importing slot values from an existing object
- Next by Date: Re: Importing slot values from an existing object
- Previous by thread: Re: static typing
- Next by thread: Re: static typing
- Index(es):
Relevant Pages
|