[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Common Lisp solved this problem 20 years ago

This page is part of the web mail archives of SRFI 77 from before July 7th, 2015. The new archives for SRFI 77 contain all messages, not just those from before July 7th, 2015.



Taylor Campbell wrote:
I'm a bit unclear on one part of your proposal: is the type
declaration syntax merely a suggestion to the compiler, or does it
actually affect the semantics of a program?

The latter, but perhaps not quite the way you're thinking.
(let ((V :: TYPE init)) ...)
has semantics like:
(let ((V (coerce-to-TYPE init))) ...)

One could also specify that within the scope of V that
(set! V exp)
gets translated to:
(set! V (coerce-to-TYPE exp))
though I don't believe Kawa actually does that.  (I'd have to check.)

That is, if I specify
that an expression's value is an IEEE double-precision flonum, do
arithmetic operations in that context 'become' IEEE 64-bit flonum
operations, with roundoff &c. as specified by IEEE, or may the system
actually do something else?

Neither: it's not the operations that change: It's the
operand that changes.  The operation + is already defined so that
if the operands are IEEE 64-bit *values* then we use 64-bit flonum
flonum addition etc.  But's that's the way R5RS already works - we're
just being more precise and allowing for more data types.

Would this be the case with the integer
declarations and n-bit modular arithmetic as well?

The declarations coerce to an appropriate data type.
I.e. you coerce an integer to a (modulo-int N), and arithmetic
on the (modulo-int N) *type* is defined to be modular.

While type declarations are useful (though I *abhor* the :: syntax),

It's not the most elegant syntax, but finding something better that
works in the context of the existing Scheme language isn't trivial.
Suggestions welcome.  I'm not fond of the Common Lisp syntax, with
its verbosity and weird scoping rules.
--
	--Per Bothner
per@xxxxxxxxxxx   http://per.bothner.com/