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!
==Code examples== ===Hello World=== Here are three ways to say "Hello world!" on a Lasso page. <syntaxhighlight lang="lasso"> <?lasso 'Hello World!' ?> ['Hello world!'] Hello world! </syntaxhighlight> Square brackets are reserved in Lasso, so HTML entities must be used to show square brackets on Lasso pages for other purposes than marking Lasso tags. Alternatively, printing square brackets can be by Lasso or be disabled by including [no_square_brackets] at the file top. ===Inlines=== <syntaxhighlight lang="lasso"> // Find all records in a table inline( -database='db_name', -table='table_name', -findall ) => { // Iterate through and process each row rows => { // Output each row to the current web request content_body += '<a href="' + column('url') + '">' + column('title') + '</a>' } } </syntaxhighlight> Inlines are the basic Lasso tool for database actions. [http://www.lassosoft.com/lassoDocs/languageReference/obj/inline Database commands] can be issued as above, in Lasso's db-independent metalanguage, in which case the same search code works for MySQL, FileMaker Pro or for any other database backend with which Lasso can connect. If needed, a [[SQL]] statement can of course be embedded in the inline when using a database server that supports SQL: <syntaxhighlight lang="lasso"> // Execute SQL statement inline( -database='db_name', -sql = 'SELECT * FROM table_name' )... </syntaxhighlight> In the above example, the dashes (-) before commands denote optional parameters. These can be specified in any order and generated dynamically; the last of any duplicate parameters take precedence. The inline command supports a large range of parameters<ref>[http://www.lassosoft.com/lassoDocs/languageReference/obj/inline large range of parameters]</ref> allowing developers to interact with databases that they may not have intimate knowledge of. Custom database connectors can be created which allows leveraging the abstracted nature of the inline command. ===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)