Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Lasso (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===99 Bottles of Beer=== The next procedural example prints out the lyrics for the song "99 Bottles of Beer". <syntaxhighlight lang="lasso"> // Define a couple of useful methods define br => '<br/>' define bottles(n::integer) => #n != 1 ? ' bottles' | ' bottle' // Declare the local that will store the lyrics as a string local(out = '') // Use Lasso query syntax to generate the lyric with n in 99 to 1 by -1 do { #out += #n + bottles(#n) + ' of beer on the wall, ' + br #out += #n + bottles(#n) + ' of beer; ' + br #n-- #out += 'Take one down, pass it around, ' + br #out += #n + bottles(#n) + ' of beer on the wall. ' + (br * 2) } // Output result #out </syntaxhighlight> The next example uses an OOP approach to print out the lyrics when the object is represented as a string: <syntaxhighlight lang="lasso"> // Define type define bottles_of_beer => type { // Define internal data data private bottles = 99 // Define private methods private br => '<br/>' private s => .bottles != 1 ? 's' | '' // Generate lyrics when object represented as a string public asstring => { local(out = '') // Use Lasso query syntax to generate the lyrics with n in 99 to 1 by -1 do { .bottles = #n #out += .bottles + ' bottle' + .s + ' of beer on the wall, ' + .br #out += .bottles + ' bottle' + .s + ' of beer; ' + .br .bottles-- #out += 'Take one down, pass it around, ' + .br #out += .bottles + ' bottle' + .s + ' of beer on the wall. ' + (.br * 2) } // Return result return #out } } bottles_of_beer </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)