Author Topic: [Tutorial] Edition 2: Using Axe to its full functional form λ  (Read 21525 times)

0 Members and 1 Guest are viewing this topic.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #30 on: July 28, 2011, 09:55:39 pm »
So, is this just going to never be in the new "Tutorials" section?  I've asked like 5 times in 3 separate threads, and I'm pretty much forced to give up all hope.  People who want to see this will have to follow the new "this is outdated link" in the old tutorial, I guess :/
Nope, you can add it now. :D

If you'd like, I can add it for you.  Just let me know. :)

Ashbad

  • Guest
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #31 on: July 28, 2011, 09:57:54 pm »
So, is this just going to never be in the new "Tutorials" section?  I've asked like 5 times in 3 separate threads, and I'm pretty much forced to give up all hope.  People who want to see this will have to follow the new "this is outdated link" in the old tutorial, I guess :/
Nope, you can add it now. :D

If you'd like, I can add it for you.  Just let me know. :)

orly?

I didn't know I could add this.. Sorry for the bitching :P

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #32 on: July 28, 2011, 10:06:17 pm »
So, is this just going to never be in the new "Tutorials" section?  I've asked like 5 times in 3 separate threads, and I'm pretty much forced to give up all hope.  People who want to see this will have to follow the new "this is outdated link" in the old tutorial, I guess :/
Nope, you can add it now. :D

If you'd like, I can add it for you.  Just let me know. :)

orly?

I didn't know I could add this.. Sorry for the bitching :P
It actually just got changed: http://ourl.ca/12282

I didn't know how to do it before, so that's why I never offered until now. ;)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #33 on: July 28, 2011, 10:42:12 pm »
Well to be honest after I left the tutorials section kinda got abandonned. No more tutorials got added, but now that they can be added by their respective authors too, this should help a lot speeding up the process.

Offline WaeV

  • LV0 Newcomer (Next: 5)
  • Posts: 3
  • Rating: +4/-0
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #34 on: September 19, 2011, 09:33:20 pm »
Hey guys, I was really impressed by these new features of Axe, so I decided to register to make this post!  I figured we could use a non-trivial example of how lambdas can be actually used.


This is an example of some functional code that we wrote in one of my programming classes.  The objective was to write a function that creates iterators.  Each time you call the iterator, it returns one more than the previous call.  We do this with lambda syntax and closures.  We wrote this in Scheme, but I was surprised and impressed to see it correctly execute in Axe.

The Axe code:
(I used liberal amounts of spaces to get it to line up the way I did)
Code: [Select]
.ITERATE

Iter()→L

Disp (L)()►Dec,i
Disp (L)()►Dec,i
Disp (L)()►Dec,i

Iter()→M

Disp (M)()►Dec,i
Disp (M)()►Dec,i
Disp (L)()►Dec,i

Lbl Iter
Return
λ(
  λ(
    λ(
      r₁+1→r₁
    )
  )(0)
)()

Output:
Code: [Select]
asm(prgmITERATE
    1
    2
    3
    1
    2
    4

An interesting side-effect of this is that the current iteration is not stored in any variables - it's captured in the closure.  Not that it's efficient to do this on a calculator with limited memory, but...
« Last Edit: September 20, 2011, 06:32:23 pm by WaeV »

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #35 on: September 20, 2011, 09:52:41 pm »
That's pretty cool!

You should post that in the Axe Routines Thread

I don't know much about functional programming -- is it possible to pass in an arbitary lambda to the iterator generator so that it can iterate over a sequence of numbers other then just '1 2 3 4'?

My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline WaeV

  • LV0 Newcomer (Next: 5)
  • Posts: 3
  • Rating: +4/-0
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #36 on: September 21, 2011, 02:11:02 am »
Yeah sure!  You can do that. The outer lambda returns the inner lambda - your phrase "iterator generator" is a good one - but it could return any lambda.

Edit: Here's a version which lets you decide where to start.
The Axe code:
Code: [Select]
.ITERATE

Iter(10)→L

Disp (L)()►Dec,i
Disp (L)()►Dec,i
Disp (L)()►Dec,i

Lbl Iter
Return
λ(
  λ(
    λ(
      r₁+1→r₁
    )
  )(r₁)
)()

Output:
Code: [Select]
asm(prgmITERATE
    11
    12
    13
« Last Edit: September 21, 2011, 06:20:00 pm by WaeV »

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #37 on: October 23, 2011, 10:08:27 pm »
What are the r1, r2, etc.?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #38 on: October 23, 2011, 11:02:35 pm »
Subroutine arguments, as in sub(LBL,1,2,3) calls LBL with 1 in r1, 2 in r2, and 3 in r3.




Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #39 on: October 23, 2011, 11:27:52 pm »
Hey guys, I was really impressed by these new features of Axe, so I decided to register to make this post!  I figured we could use a non-trivial example of how lambdas can be actually used.


This is an example of some functional code that we wrote in one of my programming classes.  The objective was to write a function that creates iterators.  Each time you call the iterator, it returns one more than the previous call.  We do this with lambda syntax and closures.  We wrote this in Scheme, but I was surprised and impressed to see it correctly execute in Axe.

The Axe code:
(I used liberal amounts of spaces to get it to line up the way I did)
Code: [Select]
.ITERATE

Iter()→L

Disp (L)()►Dec,i
Disp (L)()►Dec,i
Disp (L)()►Dec,i

Iter()→M

Disp (M)()►Dec,i
Disp (M)()►Dec,i
Disp (L)()►Dec,i

Lbl Iter
Return
λ(
  λ(
    λ(
      r₁+1→r₁
    )
  )(0)
)()

Output:
Code: [Select]
asm(prgmITERATE
    1
    2
    3
    1
    2
    4

An interesting side-effect of this is that the current iteration is not stored in any variables - it's captured in the closure.  Not that it's efficient to do this on a calculator with limited memory, but...

I can't replicate your output?  I get 1,2,3,1,2,3.  I think the issue is that you believe r1-r6 to be local variables to each function, but in fact they are global?

Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #40 on: October 24, 2011, 07:46:08 pm »
Subroutine arguments, as in sub(LBL,1,2,3) calls LBL with 1 in r1, 2 in r2, and 3 in r3.

What's a subrouine argument?P

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #41 on: October 25, 2011, 10:52:00 am »
a subroutine argument is a value you give to a subroutine.
I'm not a nerd but I pretend:

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #42 on: October 25, 2011, 06:09:03 pm »
Do this:

prgmTEMP

.STUFF

ClrHome

Stuff(1)

Pause 3000
Return

Lbl Stuff
Disp r1>Dec
Return

..end of prgmTEMP

Compile it, run prgmSTUFF, and it will display the letter 1.
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline epic7

  • Chopin!
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2200
  • Rating: +135/-8
  • I like robots
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #43 on: October 25, 2011, 06:51:32 pm »
a subroutine argument is a value you give to a subroutine.

How would you use a value given to a subroutine?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: [Tutorial] Edition 2: Using Axe to its full functional form λ
« Reply #44 on: October 25, 2011, 07:14:43 pm »
epic7, have you read the Axe user guide?  It has a lot of answers to a lot of the questions you have been having :)  To pass an argument to a subroutine, you would type Sub(ARG) where ARG is put into r1 when the routine is called