Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 02-26-2021, 09:38 AM   #1
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Request for comments: new template language operations

I am adding "standard" binary and unary logical and arithmetic operators to the template language. The question: "what is the precedence of the operators?"

In line with other languages, my own preferences, and the characteristics of the existing language; the current choice from highest to lowest (binding first to last) is:
  • Function calls, constants, parenthesized expressions, statement expressions, assignment expressions. Remember that in the template language, 'if', 'for', and assignment return a value.
  • Unary plus (+) and minus (-). Although I can't see why it matters, these operators evaluate right to left. These and the other arithmetic operators return integers if the expression doesn't produce a fractional part.
  • Multiply (*) and divide (/). These operators are associative and evaluate left to right. Use parentheses if you want to change the order of evaluation.
  • Add (+) and subtract (-). These operators are associative and evaluate left to right.
  • Numeric and string comparisons (these already exist). These operators return '1' if the comparison is True, otherwise ''. Comparisons are not associative:
    a < b < c produces a syntax error. Comparisons return '1' if True and '' if False.
  • Unary logical not (!). This operator returns '1' if the expression is False (evaluates to the empty string), otherwise ''.
  • Logical and (&&). This operator returns '1' if both the left-hand and right-hand expressions are True, the empty string '' if either is False, is associative, evaluates left to right, and does short-circuiting.
    Spoiler:
    Regarding short-circuiting: for example this program produces the answer '4'. Because of short-circuiting the right-hand expression, the assignment, is evaluated because the left-hand expression is True. The assignment is done.
    Code:
    program:
    	a = 5;
    	'a' && (a = 4);
    	a
    This program produces '5' because the the left-hand expression is False so because of short-circuiting the right-hand expression is not evaluated. The assignment is not done.
    Code:
    program:
    	a = 5;
    	'' && (a = 4);
    	a
  • Logical or (||). This operator returns '1' if either the left-hand or right-hand expression is True, '' if both are False, is associative, evaluates left to right, and does short-circuiting. It does an inclusive or, returning '1' if both the left- and right-hand expressions are True.
chaley is offline   Reply With Quote
Old 02-26-2021, 10:38 AM   #2
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,090
Karma: 1948136
Join Date: Aug 2015
Device: Kindle
Those change are most welcome. I leave the discussion about the order of precedence for people who know more about the subject than I do. It is fine with me so long as I can explicitly set the order using parenthesis.
capink is offline   Reply With Quote
Advert
Old 02-27-2021, 12:17 AM   #3
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Yes please! Those will be great additions.

The precedence looks good to me. It matches most languages I have used and I can't see anything missing.
davidfor is offline   Reply With Quote
Old 02-27-2021, 12:09 PM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The changes are in calibre master source. It would be very useful if people who run from source try it and let me know about problems, and in particular any backwards compatibility issues.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template language changes chaley Library Management 132 03-03-2024 06:34 PM
A few questions... (template language, mainly) Clem2605 Library Management 2 12-30-2020 03:25 AM
Template Language phossler Calibre 8 01-12-2016 04:37 PM
Help with template language Pepin33 Calibre 8 11-11-2012 08:32 AM
Template language question BookJunkieLI Library Management 7 02-02-2012 06:55 PM


All times are GMT -4. The time now is 12:33 AM.


MobileRead.com is a privately owned, operated and funded community.