Bm 1 — Bill’s Jan 2023 memento — Introduction to Bill’s mementos
I hope you’re having a happy 2023 so far! This is the first edition of my mementos — newsletters for the Memento forum about our use of Memento. They'll be published in my native American English as Memento Forum posts on a periodic basis (maybe every month or two). After a short introduction, one or more articles on the use of Memento will appear. Some of it will be topical commentary, but most will be articles intended to be informative & helpful to users who are trying to get the most out of Memento as they use it to do anything from making shopping lists to building database applications.
The kinds of articles I’ve planned to write in my mementos…
Getting started with your first library, then just a bit more (or not), then a bit more, …
Topics for discussion, eliciting contribution via replies to whatever contribution I start with
Growing a simple Memento library into a database with libraries linked together & maybe scripted to turn it into a database application. (My general approach: Library + links = database (⇒template file) + scripts = application (⇒catalog template) ).
How to design a database of linked libraries
I’m extremely open to recommendations for future topics! Let me know what our’re interested in seeing by sending me a private email or post back to the thread -- whichever seems more appropriate.
Bill’s mementos (Bm) are intended to be kept as mementos for future reference, as they contain essential information about Memento & its use. To this end, I am setting up the Subject line format, article titles, and hashtags (like #Tutorial) in a standard way so forum members can readily search, find things, and make use of this information as time moves on. Also, the mementos will be archived in the Memento Wiki. See the first section in the Navigation Index in the last column.
A literal is something you type that represents a value. The most prominent two kinds of literals are numbers and strings (strings of characters that make up text).
12 is a number, and "12" is a string. I almost always use double-quotes to designate a string, but so long as they are a matched pair, you could use single-quotes instead, like '12'. "Bill's mementos" is a string, and the single-quote or apostrophe inside works like any other character. There's nothing special about it, since it's protected by being inside a string.
A literal is the most fundamental expression. There is no calculation or other operation occurring – the value of the expression is merely the value of the literal.
Variable names must start with a letter, underscore, or dollar sign ($), and can contain alphabetic, numeric, or underscore characters after that. By convention, by default, variable names start with a word in lowercase and are followed by any remaining words needed to clearly identify the variable. Each of these following words begin with a capital letter. For example, a is a conventional variable name, as are aLamb and aLittleLamb -- 3 distinct variables, each with its own value. Because a variable is a holder for a value, that value is its value, so variables can be used in expressions just as literals can.
Scripts consist of a sequence of statements.
var x = 12; // 2 slashes like this make the rest of the line just commentary.
// The statement above defines a variable x and sets its value to 12.
A second way of including a comment in a script is to begin the comment with "/*" and end it with */". For example…
var y = 34; /* This kind of content may begin and end on one line
or continue across multiple lines. */
The var statement causes a variable to be defined and a name assigned to it. Optionally, an initial value can also be assigned to it. A variable is similar to a variable in algebra.
Note: The var keyword works on all Memento platforms, so that's the keyword I always use for variables in Memento scripts. Any script in Bm articles will work on any Memento platform. On the Web, you may see let and/or const used in place of var. They do not work in Memento on Android devices and may not work on iOS devices due to a limitation in Memento in the mobile edition.
var x = 12; var y = 23; var z = 34;
/* Another statement */
= 12; // A line break is treated just like a space.
The literal 12 depicts a number -- a dozen. The literal "12" depicts a 2-character string -- a "1" followed by a "2". It looks the same when displayed on the screen, but it's difficult to reliably do numeric calculations with a string. One reason why is that, during evaluation, operators will very likely automatically convert a number to a string before the operation takes place, and the result may not be what you intended. More on this below.
An operator is a symbol that represents an operation that is to be executed. We've already used the = operator in the var statements above. What it does might surprise you. It sets the value of the operand (variable) on its left to the value of the expression that is on its right (the right operand). It's not used for comparisons. I'll discuss comparisons starting in Chapter 2. The other most common operators for calculation are + to add, - to subtract, * to multiply, and / to divide. There are many more, but these will do for now. These are called binary operators because they operate on an operand on its left and another on its right. The result is a value. For instance…
var x = 12; var y = 23; var z = x + y; // Afterwards, z is 35
The + operator can be used on strings, as well, but it works very differently…
var first = "Bill"; var last = "Crews"; var z = first + last; // z is "BillCrews"
Woops! There's no space between them! To handle that, we could say…
var z = first + " " + last; // z is now "Bill Crews", or we could say…
var z = last + ", " + first; // z is now "Crews, Bill"
If you want to add something to a variable or otherwise perform an operation on a variable, add an equal symbol (=) to the operator. This works for the 4 operators we've discussed so far and for many others you'll learn about later. For example…
x +=1; // Add 1 to x. If x was 1, it is now 2
x -= y; // Subtract y from x. If x was 2 and y was 1, x will now be 1 again
x = (y + 1) * (z - 2); // If y was 3 and z was 4, x will now be 8
If we had omitted the parentheses, the result might not be what you intended…
field("unitPrice") * field("quantity"); // You need no variables for this.
So far, we've studied 2 kinds of statements: a declaration statement (var) and an expression statement. Expressions are often parts of larger statements rather than independent statements of their own.
To install the library, download the template from the Online Catalog and add your library based on the template BmExpressions.mlt2.