View Single Post
Old 03-26-2022, 07:19 PM   #364
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: 12,529
Karma: 8075938
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
This now works. I need to play a bit more with it.
Code:
program:
	days = 2112;
	years = floor(days/360);
	months = floor(mod(days, 360)/30);
	days = days - ((years*360) + (months * 30));

	def to_plural(v, str):
		if v == 0 then return '' fi;
		return v & ' ' & (if v == 1 then str else str & 's' fi) & ' '
	fed;

	to_plural(years, 'year') & to_plural(months, 'month') & to_plural(days,'day')
The '&' operator (strcat) is there and used in the above template.

I decided to use the same syntax to define functions as used everywhere else, defining the function body with def/fed instead of {}. This is like if/fi and for/rof. As well as being consistent it avoids some problems with matching blocks and also makes using semicolons more consistent.
Attached Thumbnails
Click image for larger version

Name:	Clipboard01.jpg
Views:	1009
Size:	42.3 KB
ID:	192963  
chaley is offline   Reply With Quote