Re: static typing



Nathan Baum <nathan_baum@xxxxxxxxxxxxxx> writes:
For example, if you have a tree of nodes with a label and a variable
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))
[...]
This doesn't completely solve the problem. There's no standard way to
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.
.



Relevant Pages

  • C Bibliography
    ... The basics are covered too, with lists, queues, double linked lists, stacks, etc. ... It covers the whole grammar and the standard library with each part of it described in detail. ... C Programming FAQs contains more than 400 frequently asked questions about C, ... jacob at jacob point remcomp point fr ...
    (comp.lang.c)
  • Re: META: how-to ruin a perfectly good FGS
    ... search engine is friendlier to special characters. ... It lists the ... Windows is the defacto "standard" operating system for most PCs ...
    (soc.genealogy.methods)
  • Re: ACCESS LIST BOX SCROLL LOCK
    ... Some of us don't like "standard" Windows control UI/Appearance, ... >> change in feature from the current version. ... >> This feature would be useful for applications where larger lists of ... >> compare similar items before proceeding with their final selection. ...
    (microsoft.public.access.forms)
  • RE: Limit bullet and numbering choices
    ... Bullet 4", "List Bullet 5" ... have special styles for lists in tables, so I check to see if the selection ... Number', 'List Number 2', etc. I'm suggesting that you use standard Word ... standard "bullets and numbering". ...
    (microsoft.public.word.vba.general)
  • Re: Lists of Figures are consecutively numbered
    ... the format requires that the label not be printed next to the ... If you want three kinds of captions to number independently, ... you will get three separate lists. ... If all your SEQ fields have the same label, or you have not used SEQ fields ...
    (microsoft.public.mac.office.word)