Hot to implement a binary operation "->"?

17 views
Skip to first unread message

Prof. Dr. Johannes Grabmeier privat

unread,
Aug 21, 2019, 2:01:02 AM8/21/19
to fricas...@googlegroups.com
would like to have a binary operation -> (or something similar, e.g. =>,
==>, -->". How to handle this properly with all these special meanings?

The code


LatticeAlgebra: Category == Join(HeytingAlgebra, Monoid,
CommutativeStar) with
  --operations

    "->":       (%, %) -> %

  add

    ((x: %) *  (y: %)): % == ...
    ((x: %) -> (y: %)): % ==. ..

compiles properly, it is shown with )show:

 ?*? : (%, %) -> %                                 ?->? : (%, %) -> %
 ?/\ : List(%) -> %                                ?/\? : (%, %) -> %
 ?<? : (%, %) -> Boolean                           ?<=? : (%, %) -> Boolean
 ?=? : (%, %) -> Boolean                           ?>? : (%, %) -> Boolean
 ?>=? : (%, %) -> Boolean                          1 : () -> %
 0 : () -> %                                       ?\/ : List(%) -> %

....


But the interpreter seems not be able to call this function:

(15) -> a

   (15)  0
                                                                        
Type: BooleanLatticeAlgebra
(16) -> b

   (16)  1
                                                                        
Type: BooleanLatticeAlgebra
(17) -> a -> b
   There are 29 exposed and 5 unexposed library operations named elt
having 2 argument(s) but
      none was determined to be applicable. Use HyperDoc Browse, or issue
                                          )display op elt
      to learn more about the available operations. Perhaps
package-calling the operation or
      using coercions on the arguments will allow you to apply the
operation.

   Cannot find a definition or applicable library operation named
Mapping with argument
      type(s)
                                       BooleanLatticeAlgebra
                                       BooleanLatticeAlgebra

      Perhaps you should use "@" to indicate the required return type,
or "$" to specify which
      version of the function you need.

(17) -> a "->" b
   There are no library operations named "->"
      Use HyperDoc Browse or issue
                                           )what op "->"
      to learn if there is any operation containing " "->" " in its name.

   Cannot find a definition or applicable library operation named "->"
with argument type(s)
                                       BooleanLatticeAlgebra

      Perhaps you should use "@" to indicate the required return type,
or "$" to specify which
      version of the function you need.

(17) -> a _-> b
   There are no library operations named a
      Use HyperDoc Browse or issue
                                             )what op a
      to learn if there is any operation containing " a " in its name.

   Cannot find a definition or applicable library operation named a with
argument type(s)
                                            Variable(-)

      Perhaps you should use "@" to indicate the required return type,
or "$" to specify which
      version of the function you need.

(17) -> a _-_> b

   >> System error:
   The value
  |b|
is not of type
  LIST


Any ideas / workarounds?

--
Mit freundlichen Grüßen

Johannes Grabmeier

Prof. Dr. Johannes Grabmeier
Köckstraße 1, D-94469 Deggendorf
Tel. +49-(0)-991-2979584, Tel. +49-(0)-151-681-70756
Tel. +49-(0)-991-3615-141 (d), Fax: +49-(0)-32224-192688

oldk1331

unread,
Aug 26, 2019, 4:25:24 AM8/26/19
to fricas...@googlegroups.com
On 8/21/19 2:01 PM, Prof. Dr. Johannes Grabmeier privat wrote:
> would like to have a binary operation -> (or something similar, e.g. =>,
> ==>, -->". How to handle this properly with all these special meanings?

I think "=>" "==>" "->" is built-in grammar, so you can't use them.

As for "-->" you can at least use them in prefix form, but
that's ugly.

> Any ideas / workarounds?
>

I think a workaround should be using ">>", "<<", or even "/\" "\/",
they seem to be supported by the scanner and parser.

Waldek Hebisch

unread,
Aug 28, 2019, 7:55:56 PM8/28/19
to fricas...@googlegroups.com
>
> would like to have a binary operation -> (or something similar, e.g. =>,
> ==>, -->". How to handle this properly with all these special meanings?

==> is used for macros, no chance for other uses. Also '=>' is too
special. '->' is an operation, but it produces types. Overloading
type producing operation would lead to creasy problem, I do not
want to think about it.
'-->' starts a comment.

ATM avaliable operators are hardcoded in 'scan.boot' and interpreter
grammar is also hardcoded. We could probably add some new arrow
operators like '=->', '-+>', '~>' or ':->'.

If we seriously think about user defined operators then
we probably need to have some rule which specify form of
possible operators. Spad parser allows adding operator
symbols at runtime and in principle the same could be done
for interpreter parser, but adding operators to scanner would
be problematic so for scanner we need a rule.


--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages