Example : vector_sum : Generate a vector and add it up

Moderator: Dr.BeauWebber

Example : vector_sum : Generate a vector and add it up

Postby Dr.BeauWebber » Thu Jun 13, 2013 12:28 am

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.
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England

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

Postby shr » Sun Aug 04, 2013 10:48 pm

So you're supporting APL glyphs and not just keywords?
“At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation” — Igor Sikorsky
shr
 
Posts: 23
Joined: Mon Dec 17, 2012 3:29 am
Location: Lyons, Colorado, USA

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

Postby Dr.BeauWebber » Sat Sep 14, 2013 3:23 am

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
User avatar
Dr.BeauWebber
 
Posts: 114
Joined: Mon Dec 17, 2012 4:01 am
Location: England


Return to APL

Who is online

Users browsing this forum: No registered users and 0 guests