33 — Habit tracker: a mark for each day
A habit tracker is one answer per date, which makes it a record whose names are dates. And the dates are not typed by hand — the computer is asked for them.
Steps
Open the date tools and work out today, yesterday and the day before.
agogoes backwards andfrom nowgoes on:
run it →use date latest set stamp to today set before to yesterday set earlier to 2 days ago show stamp show before show earlierUse the date as the name the answer goes under:
run it →use date latest set log to an empty record set stamp to today put stamp at yes in log show stamp in logYou get
yes. A name in the name position means the date inside it becomes the name.Today's answer is asked for:
run it →use date latest set log to an empty record set stamp to today ask reply did you do it today put stamp at reply in log show how many logCounting the days is a walk with a comparison. Take the value out and compare it:
run it →set log to an empty record put Monday at yes in log put Tuesday at no in log set done to 0 for each day in log set mark to day in log if mark equals yes add 1 to done end end show doneYou get
1.The whole thing:
run it →use date latest set log to an empty record set stamp to today set before to yesterday set earlier to 2 days ago put earlier at yes in log put before at no in log ask reply did you do it today put stamp at reply in log for each day in log show day show day in log end set done to 0 for each day in log set mark to day in log if mark equals yes add 1 to done end end show done
Try it yourself
Count the run of days in a row — walk backwards from today and break at the
first day that is not yes. Then keep it in a file the way
guide 36 does, so the record survives closing the program.
What you learned
- One answer per date is a record whose names are dates.
yesterdayand2 days agoare the sentence way to step back;3 days from nowsteps on. Only afteruse date latest, because that is what makes them mean a date.- A name in the name position puts the value inside it there instead.
- Counting is walking, taking the value out, comparing, and adding one.