Aleksej Saushev <a...@inbox.ru> writes:

| Aleksej Saushev <a...@inbox.ru> writes:
| 
| > I seek for enlightement.
| 
| Even with all your corrections it still doesn't work,
| both this:
| 
| )abbrev package BUG Bug
| Bug(D: Type): Exports == Implementation where
|   Exports == with
|     dummy: D -> D
|   Implementation == add
|     iterte: (D -> D, D, NonNegativeInteger) -> D
|     iterte(f, p, n) ==
|       n = 0 => p
|       f(iterte(f, p, subtractIfCan(n, 1)))
                       ^^^^^^^^^^^^^^^^^^^

subtractIfCan does not return a NonNegativeInteger.  Rather, its
return type is  Union(NonNegativeInteger, "failed").
(In general, the xxxIfCan functions return a Union(D, "failed") where
D is some domain.)
Consequently, you need an explicit coercion to retrieve the
NonNegativeInteger value.  The following code compiles with OpenAxiom

)abbrev package BUG Bug
Bug(D: Type): Exports == Implementation where
  Exports == with
    dummy: D -> D
  Implementation == add
    iterte: (D -> D, D, NonNegativeInteger) -> D
    iterte(f, p, n) ==
      n = 0 => p
      f(iterte(f, p, subtractIfCan(n, 1)::NonNegativeInteger))

[...]


Personally, I would write the body of 'iterte' without too much fuss
with NonNegativeInteger, as

    iterte(f, p, n) ==
      n': Integer := n
      n = 0 => p
      f(iterte(f, p, (n' - 1)::NonNegativeInteger))

The corresponding code uses less CONS and less indirection

(DEFUN |BUG;iterte| (|f| |p| |n| $)
  (PROG (#1=#:G780 |n'|)
    (RETURN
     (SEQ (LETT |n'| |n| |BUGG;iterte|)
          (EXIT
           (COND ((EQL |n| 0) |p|)
                 ('T
                  (SPADCALL
                   (|BUGG;iterte| |f| |p|
                    (PROG1 (LETT #1# (- |n'| 1) |BUGG;iterte|)
                      (|check-subtype| (>= #1# 0) '(|NonNegativeInteger|) #1#))
                    $)
                   |f|)))))))) 



| Is there any comprehensible documentation on the syntax and semantics of
| the language?

the AXIOM book is the only written guide/reference to the language
currently available.  The rest is some form of collective folklore...

-- Gaby

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
open-axiom-devel mailing list
open-axiom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/open-axiom-devel

Reply via email to