Re: [fricas-devel] [PATCH] Minor code changes to computation.spad

2016-09-19 Thread Waldek Hebisch
Martin Baker wrote:
> 
> On 18/09/16 18:41, Waldek Hebisch wrote:
> >
> > I got caught by Spad weirdness.  In Spad
> >
> >"string"::OutputForm
> >
> > is the same as
> >
> >"string"@OutputForm
> >
> > which gives the same result as
> >
> >message("string")
> >
> > that is without string quotes.  OTOH
> >ss : String := "string"
> >ss::OutputForm
> >
> > is the same as interpreter "string"::OutputForm and adds
> > string quote.  I am thinking about removing the special
> > handling of '"string"@OutputForm' from Spad compiler.
> > There seem to be several uses of this in algebra, so there
> > is some work adjusting.  But still I think that removing this
> > irregularity is better.
> 
> I think the main problem is much simpler than that, its not doing 
> anything with the result, it should assign it to variable 's'.

Yes.  However, all I can do for this is to be more careful
and avoid distractions.  The strange behaviour of '"string"::OutputForm'
was a distraction and this we can fix.

BTW: Normal Spad style is to omit 's' and write code like

n case lf =>
(n.lf)::OutputForm
n case nd =>

...

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [fricas-devel] [PATCH] Minor code changes to computation.spad

2016-09-19 Thread Martin Baker

On 18/09/16 18:41, Waldek Hebisch wrote:

Martin Baker wrote:


Thanks for applying previous patch.

When you did this you made some changes and one of these changes
introduced a bug, so here is a fix for this bug:


I got caught by Spad weirdness.  In Spad

   "string"::OutputForm

is the same as

   "string"@OutputForm

which gives the same result as

   message("string")

that is without string quotes.  OTOH
   ss : String := "string"
   ss::OutputForm

is the same as interpreter "string"::OutputForm and adds
string quote.  I am thinking about removing the special
handling of '"string"@OutputForm' from Spad compiler.
There seem to be several uses of this in algebra, so there
is some work adjusting.  But still I think that removing this
irregularity is better.


Waldek,

I think the main problem is much simpler than that, its not doing 
anything with the result, it should assign it to variable 's'. So it 
gives empty output like this:


(1) -> UNTYP := SKICombinators Untyped

   (1)  SKICombinators(Untyped)
  Type: Type
(2) -> m1 := I()$UNTYP

   (2)
  Type:SKICombinators(Untyped)

but it should give output like this:

(2) -> m1 := I()$UNTYP

   (2)  I
  Type:SKICombinators(Untyped)

I think the code should be like this:

  -- output
  coerce(n : %) : OutputForm ==
  s : OutputForm := empty()$OutputForm
  if n case lf then
  -- leaf node so print I, K or S
  s := (n.lf)::OutputForm -- **need to assign to s here **
  if n case nd then
  -- binary node which has two subnodes c1 and c2
  if atom?(n.nd.c2) then
  if variable?(n.nd.c2) then
  s := hconcat([s,_
(n.nd.c1)::OutputForm,_
message(" "),_
(n.nd.c2)::OutputForm])$OutputForm
  else
  s := hconcat([s, (n.nd.c1)::OutputForm,
(n.nd.c2)::OutputForm])$OutputForm
  else
  s := hconcat([s,(n.nd.c1)::OutputForm,message("("),_
 (n.nd.c2)::OutputForm,message(")")])$OutputForm
  if n case vr then
  -- variable node so print name
  s := (n.vr)::OutputForm
  s

Martin B

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [fricas-devel] [PATCH] Minor code changes to computation.spad

2016-09-18 Thread Waldek Hebisch
Martin Baker wrote:
> 
> Thanks for applying previous patch.
> 
> When you did this you made some changes and one of these changes 
> introduced a bug, so here is a fix for this bug:

I got caught by Spad weirdness.  In Spad

   "string"::OutputForm

is the same as

   "string"@OutputForm

which gives the same result as

   message("string")

that is without string quotes.  OTOH
   ss : String := "string"
   ss::OutputForm

is the same as interpreter "string"::OutputForm and adds
string quote.  I am thinking about removing the special
handling of '"string"@OutputForm' from Spad compiler.
There seem to be several uses of this in algebra, so there
is some work adjusting.  But still I think that removing this
irregularity is better.

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [fricas-devel] [PATCH] Minor code changes to computation.spad

2016-09-17 Thread Martin Baker

On 17/09/16 06:00, oldk1331 wrote:

I want to have
print "a string"
insead of
print("a string"::OutputForm)
when I am debugging.

I tried to add a "print : String -> Void", but not successful.
What's the right way to do it?


I also asked about something like this in thread here:

https://groups.google.com/forum/?hl=en#!topic/fricas-devel/ouZg285DTcI

In this thread I think the long term solution is given by Waldek:

Waldek Hebisch wrote:
> I thought about easier debugging printouts
> from Spad and I see the following possibilities:
>
> - teach Spad compiler to allow "open types", that is types
>  for which compiler can infer type of parameter.  That
>  would allow something like:
>
>print(x)
>
>  with Spad compiler automatically choosing appropriate
>  overloaded version of 'print' matching type of 'x',
>  after a single import like:
>
>import from PrintPackage1(?)
>
>  where '?' means that we allow all types of arguments.
>
> - Use infix operator plus overloading for printing, like:
>
>   d_out << "abc" << 1
>
>  with overloaded versions of '<<' it could print any type.
>  Note: to avoid a lot of imports that requires either adding
>  '<<' to all domains or "open types" like above.
>
> "open types" would require change to Spad compiler.  Using '<<'
> with explicit import is just matter of writing appropriate
> package.  In principle we could add '<<' to SetCategory or
> even to 'CoercibleTo(OutputForm)' (using conditional export
> in 'CoercibleTo').

I hope a solutions like these can be implemented, I don't have the 
knowledge to do anything myself.


Martin B

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [fricas-devel] [PATCH] Minor code changes to computation.spad

2016-09-16 Thread Waldek Hebisch
Martin Baker wrote:
> 
> On 15/09/16 19:49, Waldek Hebisch wrote:
> > Martin Baker wrote:
> >>
> >> Minor code changes to computation.spad
> >> 1) Change sayMsg to print.
> >> 2) Improve OutputForm, don't use string.
> >> 3) implement CoercibleTo(OutputForm).
> >
> > I see that you have a lot of code like:
> >
> >   str::Symbol::OutputForm
> >
> > If you want to print string without quotes use 'message':
> >
> >   message(str)
> >
> > gives you desired OutputForm.  For nonconstant strings
> > this is more efficient and in all cases is clearer
> > than going via symbols.
> 
> OK, I have done that.
> 
> Updated file is here:
> https://github.com/martinbaker/multivector/blob/master/computation.spad
> and patch is here:
> https://github.com/martinbaker/multivector/blob/master/computation3.patch
> 
> This compiles and works so, as far as I can tell, its ready to go. There 
> is just one thing that I'm curious about. I now have lot of lines like this:
> 
> print(message "warning I does not have a parameter to act on")
> 
> This generates a compiler error like this:
> 
> compiling exported coerce : SKICombinators UT -> ILogic
> ** comp fails at level 11 with expression: **
> error in function coerce
> 
> ** level 11  **
> $x:= (message warning I does not have a parameter to act on)
> $m:= $EmptyMode
> $f:=
> #:G6598 # #) (#:G6601 # #) (|s| # #) (|lambdaOverSki| #))
>((|lambdaOverSki| #) (= #) (I #) (K #) ...)
>((|Ski2Lambda| #) (= #) (|atom?| #) (|bind| #) ...)))
> 
> >> Apparent user error:
> NoValueMode
>  is an unknown mode
> 
> I assume this is because there are 2 print functions with the same 
> signature (although the error message gives no clue to this).
> 
> So I changed the line to:
> print(message "warning I does not have a parameter to act on")$OutputForm
> 
> and this makes the error go away.
> 
> The interesting thing is, I only have to do this once (see line 2794 in 
> code) and then all other similar functions compile without specifying 
> domain. Its like I only have to tell the compiler which version of 
> 'print' to use once and it then uses the same for all future 'print' calls.
> 
> So, my questions are:
> 1) Are my suppositions correct?
> 2) If so, is it safe to rely on it?

No.  The real thing is that Spad compiler considers only functions
from "visible" domains.  Main way to make domain visible is to
import it:

  import OutputForm

Currently Spad compiler performs implicit import in some situations.
In particular 'f()$Dom' as a byproduct imports Dom.  This is a
misfeature and sooner or later will go away.

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [fricas-devel] [PATCH] Minor code changes to computation.spad

2016-09-16 Thread Martin Baker

On 15/09/16 19:49, Waldek Hebisch wrote:

Martin Baker wrote:


Minor code changes to computation.spad
1) Change sayMsg to print.
2) Improve OutputForm, don't use string.
3) implement CoercibleTo(OutputForm).


I see that you have a lot of code like:

  str::Symbol::OutputForm

If you want to print string without quotes use 'message':

  message(str)

gives you desired OutputForm.  For nonconstant strings
this is more efficient and in all cases is clearer
than going via symbols.


OK, I have done that.

Updated file is here:
https://github.com/martinbaker/multivector/blob/master/computation.spad
and patch is here:
https://github.com/martinbaker/multivector/blob/master/computation3.patch

This compiles and works so, as far as I can tell, its ready to go. There 
is just one thing that I'm curious about. I now have lot of lines like this:


print(message "warning I does not have a parameter to act on")

This generates a compiler error like this:

   compiling exported coerce : SKICombinators UT -> ILogic
** comp fails at level 11 with expression: **
error in function coerce

** level 11  **
$x:= (message warning I does not have a parameter to act on)
$m:= $EmptyMode
$f:=
#:G6598 # #) (#:G6601 # #) (|s| # #) (|lambdaOverSki| #))
  ((|lambdaOverSki| #) (= #) (I #) (K #) ...)
  ((|Ski2Lambda| #) (= #) (|atom?| #) (|bind| #) ...)))

   >> Apparent user error:
   NoValueMode
is an unknown mode

I assume this is because there are 2 print functions with the same 
signature (although the error message gives no clue to this).


So I changed the line to:
print(message "warning I does not have a parameter to act on")$OutputForm

and this makes the error go away.

The interesting thing is, I only have to do this once (see line 2794 in 
code) and then all other similar functions compile without specifying 
domain. Its like I only have to tell the compiler which version of 
'print' to use once and it then uses the same for all future 'print' calls.


So, my questions are:
1) Are my suppositions correct?
2) If so, is it safe to rely on it?

Martin B

--
You received this message because you are subscribed to the Google Groups "FriCAS - 
computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.


Re: [fricas-devel] [PATCH] Minor code changes to computation.spad

2016-09-15 Thread Waldek Hebisch
Martin Baker wrote:
> 
> Minor code changes to computation.spad
> 1) Change sayMsg to print.
> 2) Improve OutputForm, don't use string.
> 3) implement CoercibleTo(OutputForm).

I see that you have a lot of code like:

  str::Symbol::OutputForm

If you want to print string without quotes use 'message':

  message(str)

gives you desired OutputForm.  For nonconstant strings
this is more efficient and in all cases is clearer
than going via symbols.

-- 
  Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To post to this group, send email to fricas-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.