Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add if and while to Lisp #418

Merged
merged 10 commits into from
Oct 21, 2022
Merged

Add if and while to Lisp #418

merged 10 commits into from
Oct 21, 2022

Conversation

vinc
Copy link
Owner

@vinc vinc commented Oct 18, 2022

  • Replace the loop form that was just infinitely looping into a while form that will stop when the condition is not true anymore
  • Add the if form
  • Use def instead of define by default

@vinc
Copy link
Owner Author

vinc commented Oct 18, 2022

This improved pi.lsp computation. It is now only 4 times slower than the native pi command and its argument is the number of digits that will be computed, not the number of iterations.

> time pi 1000
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989
Executed 'pi 1000' in 0.055144s

> time lisp /tmp/lisp/pi.lsp 1000
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201981
Executed 'lisp /tmp/lisp/pi.lsp 1000' in 0.179125s

@vinc vinc changed the title Change Lisp loop into while Add if and while to Lisp Oct 18, 2022
@vinc vinc marked this pull request as ready for review October 21, 2022 08:03
@vinc vinc merged commit fcf3a7e into trunk Oct 21, 2022
@vinc vinc deleted the feature/lisp-while branch October 21, 2022 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant