-
Notifications
You must be signed in to change notification settings - Fork 7
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
builtin: Add rand
and strings functions
#82
Conversation
firebase-deployment: https://evy-lang--82-r0m72zv4.web.app (5348d79) |
a1a2917
to
a4bf6e3
Compare
From Mali: hey mum, the sample code would be better like this:
|
rand
and strings functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🦚 LGTM
I noticed when I tried the guessing game that the input line was not focused, so I typed a number (nothing happened) and I pressed enter, and that stopped the program because the Stop button was still focused. Perhaps calling read
should focus on the input?
Also, I guessed the right number 3 times, so I think I deserve a cookie.
frontend/samples/rand.evy
Outdated
|
||
while guess != n | ||
if guess > 10 | ||
print guess "Guess higher (1-10)." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be "Guess lower" and the next "Guess higher"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍪
thanks for the review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this up.
Your comment re input focus is a really good one. also fixed.
Only load evy source via URL fragment for 2xx response.
Add random number generation functions: * rand n returns an integer in the half open interval [0,n) * rand1 returns an float64 in the half open interval [0,1) This functions are mapped to Go's math/rand package. It seems that tinygo still requires seeding (tested). Add a demo for clarity. Focus input textbox when jsRead is called for better usability.
Add more strings functions for good measure and because it was the only thing I was capable of on this hot afternoon.
Add random number generation functions:
rand n
returns an integer in the half open interval [0,n)rand1
returns an float64 in the half open interval [0,1)Add string functions
upper
,lower
,index
,trim
,startswith
,endswith
,replace
.This functions are mapped to Go's math/rand package. It seems that
tinygo still requires seeding (tested).
Add a demos for clarity.
Minor bug fix for non 2xx source response: don't load random HTLM,
write error to console instead.
https://evy-lang--82-r0m72zv4.web.app/#source=samples/rand.evy&show=.read
https://evy-lang--82-r0m72zv4.web.app/#strings