Page 1 of 1

Example : vector_sum : Generate a vector and add it up

PostPosted: Thu Jun 13, 2013 12:28 am
by Dr.BeauWebber
Create a vector 1 to 9;
add the vector using a plus reduction :
Code: Select all
      V ← ⍳ 9
      V
1 2 3 4 5 6 7 8 9
      S ← +/V
      S
45

Which in the ascii notation used by aplc looks like :
vector_sum.apl :
Code: Select all
V .is .io 9
# .is V
S .is +/V
# .is S

The c code aplc generates at the moment has to be slightly edited (I aim to write a .sed script to do this.), so as to convert the fprintf statements to sprintf, to write to the output buffer.
This then outputs :
Code: Select all
  0: Message from eCore 0x8ca ( 3, 2): " 1 2 3 4 5 6 7 8 9
 45
"
  1: Message from eCore 0x84b ( 1, 3): " 1 2 3 4 5 6 7 8 9
 45
"

etc.
Which is correct.

Re: Example : vector_sum : Generate a vector and add it up

PostPosted: Sun Aug 04, 2013 10:48 pm
by shr
So you're supporting APL glyphs and not just keywords?

Re: Example : vector_sum : Generate a vector and add it up

PostPosted: Sat Sep 14, 2013 3:23 am
by Dr.BeauWebber
shr wrote:So you're supporting APL glyphs and not just keywords?

The glyphs are used in an APL interpreter, where I write and test the code, then I use a pre-defined APL function to translate the glyphs to the ascii .notation used by aplc.
i.e. :
Code: Select all
          ⍴  =>  .rho