Tuesday, December 19, 2023

The difference between Applicative and Concatenative programming

In the previous post, I outlined the difference between object oriented (noun.verb) and applicative (verb(noun)) programming.  The differences between the applicative and concatenative (noun verb) programming styles are a bit more subtle.  


The basic difference is in the storage of data.  Applicative programs store data in named variables.  Every piece of data at every step along the way must have an assigned name to store it for processing.  Concatenative programming makes use of a stack for passing data. All functions work on data that must already be on the stack, and leave their results on top of the stack.  As a result, you don't need to label or assign intermediate values.  You don't even have to assign the final value of a complex series of functions to a variable.  You can just leave it on the top of the stack, ready for the next function to work on.

Applicative:  Simple functions are applied to each other to create more complex functions, and their results are assigned to variable names.  The syntax is either inside out, or requires the use of intermediate variable assignments.
    final_noun = verb3(verb2(verb1(noun)))
-or-
    noun2 = verb1(noun1)
    noun3 = verb2(noun2)
    final_noun = verb3(noun3)

Concatenative:  Complex functions are created by the concatenation of simpler ones.  The syntax is the order of operations. No variable names or assignments are required.
    noun verb1 verb2 verb3


Let's say I want to construct a house, given a plot of land and materials.

Applicative:
    house = paint(build(dig(plot), materials)))
-or-
    foundation = dig(plot)
    unpainted_house = build(foundation, materials)
    house = paint(unpainted_house)
function definition:
    define construct_house(dirt: plot, stuff: materials): house =
        let home = paint(build(dig(dirt), stuff)))
        return home

Concatenative:
    plot dig materials build paint
function definition:
    define: "construct_house" [materials, plot --> house]
        {dig build paint}


Concatenative programming's strength is the lack of intermediate variable assignments, allowing a smooth flow of data through functions.  This is also its weakness, as you don't have descriptive names to show exactly what form the data is in at each step.  The reversal of data and function names also takes some getting used to, but this is balanced by the direct order of functions one after another.  Concatenative programming style may be summarized as: given this data, do this, then this, then this.

The peculiarity of concatenative programming comes from the stack.  The data must be in the correct order for the functions to operate upon.  This may require some manipulation of the data on the stack, swapping, duplicating, and deleting as necessary.  Some concatenative languages allow the use of temporary variables to make this manipulation more explicit and easier to read, at the expense of requiring temporary variable assignment and storage.

Example: The "construct house" function above requires the data to be in materials, plot order.  If these were reversed, it would be written as:

    define: "construct_house_v2" [plot, materials --> house]
        {swap dig build paint}

If the "build" function required the data to be in foundation, materials order, it would be require another swap.

    define: "construct_house_v3" [plot, materials --> house]
        {swap dig swap build paint}

For this reason, when using a concatenative programming language, much attention must be paid to the order of data used in each function.  A little planning can eliminate a lot of swapping. 

The difference between Object Oriented and Imperative programming

At its heart, programming is applying functions to data.  In normal people speech, verbs acting on nouns.  But which verbs are allowed to act on which nouns?  This question defines the split between object oriented and "standard" imperative programming.

Imperative:  verb(noun)
Verbs (functions) have a list of nouns (data types) which they may act upon.
Functions are applied to data.

Object Oriented:  noun.verb
Nouns (object classes) have a list of verbs (methods) which may act upon them.
Objects contain functions.

That's it.  That's the difference between these two programming styles.

Monday, November 27, 2023

Spinors visualized

Here is a Youtube video on the complex version of basic geometric shapes.  It's entertaining, enlightening, and beautiful.

Here is one of the final images from the video.  It's source is a simple function.  But if you look at it, you'll realize it is a graphical representation of spinors.  Spinors are a quantum effect that requires 720 degrees of rotation to return to their starting condition.  They're supposed to be really weird and without precedent in the "Real" world.  Right.  They're simple functions in the complex (4-D) plane.



Thursday, November 23, 2023

Happy Thanksgiving!

 Wishes for a happy Thanksgiving to one and all!

"We gather together to ask the Lord's blessing."



Monday, November 20, 2023

More novel goodness!

  Alma Boykin has released into the wild her latest Familiars book, "Hunter and Horseman".  This one is following the adventures of Jude, the lone and lonely defender of his rural county.  The Batman of the back country, and his nearly night-blind raptor Familiar.


  Cedar Sanderson also published a new novella, "Running Into Time".  This one is a stand-alone time travel story, inspired by some of the "weekly writing prompts" a group of authors challenge each other with.  


  Chris Nuttall has edited the seventh anthology in the series: "Fantastic Schools - Staff".  He works with quite a few good authors on these as part of the "superversive" literary movement.

Sunday, November 19, 2023

The nature of time

Time is change.  Perceived time is relative to the total energy of a particle and its environment.  Spacetime is a field of potential energy governing motion.  I've gone over all this before, but now I have something even simpler.

Proper (perceived) time is potential energy.  Period.  What kind of potential energy?  All of it.  The less energy is used by a particle, the faster time runs for it.  Proper time is properly (hah!) measured in imaginary units, but we see its effects in our real-valued universe, and its measure is almost always squared.  (The square of i is -1, by definition.)  So we mostly ignore its imaginary nature, except that comes back to bite us in general relativity, which is why the (squared) time element of the spacetime metric is negated.  (Or all three space axes are negated instead.  Same difference.)

For those not familiar with the math/geometry, the imaginary axis is 90 degrees to the real axis, satisfying the need for dimensions to be perpendicular to each other.  The imaginary direction can also represent a rate of change, satisfying the nature of time itself.

This explains spinors, by the way.  What we perceive as 360 degrees of rotation is really 180 degrees in a complex field, of which we can only measure the real valued portion.  We have no means of experiencing or measuring the imaginary valued portion, except to note that after a single passage from like to like values, the direction is opposite what we would expect.  That's exactly what happens when you rotate a point along a circle in a complex plane - the real value goes from +1, through 0, to -1.  It then passes back through 0 to +1 again.  What we perceive as two rotations is really a single one, but in a complex plane which we cannot directly perceive.  Especially when you square the function, eliminating the negative portion entirely (but leaving the problem of opposite directions to every other wave).

This is most likely the root cause of neutrino oscillation.  We simply can't directly perceive things outside of our real-valued, three dimensional space.

Yes, I realize this may sound a bit incoherent.  It's all a beautifully simple whole in my head which I have a hard time explaining.  Yes, I do realize what I just wrote.  Go ahead and laugh, but when you're done laughing, please think.  Many of these ideas are not original to me.  Minkowski himself wrote time as an imaginary component when he created the math behind 4-D spacetime and general relativity.  It was later simplified to a negative squared term, leaving out the explanatory "i".  That "i" is the whole reason for the negative term in the spacetime metric, and the cause of hyperbolic spacetime.  Euclidean space + imaginary time = hyperbolic spacetime.  The geometry is simple.  The math is horrific.

Oh, and to reiterate - there is a maximum and minimum energy density, resulting in (or from) a maximum and minimum flow of time.  Time cannot run backwards, because there can't be negative potential energy.  Time cannot exceed a certain rate, because there cannot be negative energy.  (Energy in a different direction is not negative, it's merely opposite.)

Whither redshift? And other musings on the nature of photons.

I have never seen any attempt to explain any physical process by which the expansion of space would cause redshift, or by what means the expansion of space would accelerate or decelerate.  Now, this doesn't mean there is no explanation, just that I, in looking, have never found one.  I don't claim to be a professional (or even well trained) physicist, so there are real limits to my knowledge.

That being said, this lack raises my hackles.  Results must have causes.

After a great deal of thought, I have come up with this.  If space is expanding, and if that expansion somehow causes photons to lose energy (redshift), then lower energy, longer wavelength photons would necessarily lose proportionately more energy than higher frequency, shorter wavelength photons.  This would appear as acceleration.

This thought experiment should be testable, as different frequencies of light from the same source would show ever so slightly different redshifts.  If this is true, then the expansion of space need not be accelerating.  If this s not true, the how is space expansion affecting photons, if it doesn't stretch longer waves more?  Unless the wavelength of a photon is an artifact of a point-like spin frequency, and not an inherent property.

And where does the lost energy go?  Is energy simply not conserved?  That is what the theory implies.  Remember, if energy is lost, it must be lost as some particular time and place.  For that to happen, it must go somewhere, or be transferred into some other form.  Unless all energy is slowly being reduced over the entire history of the universe, of course.  Then it would be time causing redshift, not distance.  A distinction without a difference, really, since it's all spacetime, but intellectually more satisfying.

Come to think of it, what is the wavelength of a photon newly emitted by an electron?  If the frequency is in the AM radio band, the wavelength is measured in many meters.  How would it work for a photon with a wavelength of, say, ten meters, to be emitted and then absorbed by two atoms a mere centimeter apart?  Where is the energy held in a photon?  The leading edge of a wave, with the wavelength being an artifact of its passing?  It cannot be a pointlike center of a full wave, or even the entire wave.  No, it has to be the leading edge, for something has to cause the leading edge, and nothing can travel faster than the photon itself.  It makes the most sense if the photon has a spin, and the wavelength is an artifact of the frequency of spin interacting with the EM field, trailing along behind.  But that makes the double slit experiment results rely on the passage of previous photons, negating all the "woo-hoo" effects.  That would also mean the wave function wouldn't have to exceed to speed of light (in some directions but not others) to achieve the necessary addition and subtraction effects.  (Yes, the standard explanation of the double slit diffraction grating requires a variable speed of light - for the same photon.  Measure the paths.)

I knew I liked where that thought was heading.  Has anybody ever done a double slit experiment while also shining a strong light of the same wavelength longitudinally between the grating and the detector?  I honestly don't know.  I do know that I have seen no evidence of the experiment ever actually being performed with single photons, mostly because I don't think anybody has ever found a way to create a reliable means of emitting single photons of the same wavelength from a source.  No, applying filters doesn't count, especially when the wavelength is longer than the average separation.

Saturday, November 11, 2023

The 11th hour, of the 11th day, of the 11th month

In Flanders Fields
by John McCrae


In Flanders fields the poppies blow
Between the crosses, row on row,
That mark our place; and in the sky
The larks, still bravely singing, fly
Scarce heard amid the guns below.


We are the Dead. Short days ago
We lived, felt dawn, saw sunset glow,
Loved and were loved, and now we lie,
In Flanders fields.


Take up our quarrel with the foe:
To you from failing hands we throw
The torch; be yours to hold it high.
If ye break faith with us who die
We shall not sleep, though poppies grow
In Flanders fields.





Tuesday, November 7, 2023

Support hungry authors!

Support your favorite independent authors!  They're, if not starving, probably hungry.  A bit peckish, at least.


Cedar Sanderson - The Groundskeeper 3 - My Ghoul



Friday, November 3, 2023

Toward a theory of motion (and everything)


Motion is distance over time. Notice that this fundamental concept is actually quite complex. It involves both distance and time, unified and separated by division.

I have never seen a theory of motion. That's what I've been working on since I started grasping the fundamentals of relativity. (Quantum theory is intimately related, of course.) Newton's Laws explain how things move, but not why. An object in motion remains in motion. Why?  To answer that, we must discuss spacetime.

3D space is flat (Euclidean). The Pythagorean theorem (a^2 + b^2 = c^2) works perfectly well. The complications come in when you add time. Why? Because time is imaginary. (Every dimension is at 90 degrees to all others.) The Pythagorean theorem still holds, but when you square i, you get -1, so the result is hyperbolic (a^2 - b^2 = c^2). 

Add in the principles that the total energy everywhere is a constant and spacetime is a field governing motion, and you have a fairly complete theory. Simple principles. Complicated mathematics.

Motion is, effectively, a vector (velocity).  Time (as perceived by the object) is, effectively, a spin.  These are the legs of a triangle connected by a hypotenuse whose length is c, the speed of light.  Speed and perceived time are thus intimately connected.  When one gets longer, the other must get shorter.

Why does something move?  Because it exists inside a curved bit of spacetime.  It's motion is defined by the curvature (with the direction of motion towards the lowest energy), and the curvature is defined by the momentum.  It can't speed up, because the speed vector would require more energy.  It can't slow down, because the time spin would require more energy.  So, lacking outside energy to change these, it continues on without change.  (Photons, lacking mass, don't have perceived time.  They only have motion.  They're still weird.)

Note that the curved bit of spacetime adequately explains redshift all by itself.  Photons gain energy in the forward direction, and lose energy in the opposite.  This applies to both the emitting and receiving particles.  So if they move in concert, no redshift is detected, because the gain and loss cancel.

Related - the most fundamental principles of the universe are:
  • The total energy at every point is a constant.
  • The total, over a large enough scale, of most properties other than energy, is zero.  (Charges cancel out.  Spins cancel out.  Everything except energy cancels out.)
This all implies that time is a spin.  This implies that antiparticles have an opposite time spin.  Thus, their description as "moving backwards in time" is essentially correct, but only for perceived time.  (Actual time always moves forward, regardless of everything else.  This is how photons move.  If perceived time were all there was, photons could not move, and the universe would be an unchanging, tiny ball of energy.)

This implies that the weak force, being only perceived by left-handed particles (and right handed antiparticles), is related to the spin of time.  This also implies that the negative and positive charges are opposite spins.  Electrons and positrons would, for example, maintain the same charge spin, but since the time spin would be backwards, the charge effect would also be backwards.

Side note - magnetism is caused by the tension of a moving charge.  A stationary charge causes no new deformation (tension) of the EM field.  A moving charge, since everything is limited by the speed of light, creates a build up of tension in the direction of motion, a lack of tension in the opposite direction, and sideways motion between the two - just like the waves created by a ship moving through the water.  (No, these are probably not the proper terms.  But they get the point across, don't they?)  By the way - gravity works in a remarkably similar manner, piling up in front of a moving object, and stretching out behind.  This is part of why the orbit of Mercury doesn't match Newton's predictions - the sun is in motion around the Milky Way.



Thursday, November 2, 2023

More intuitive spacetime interval

Space is Euclidean.  Spacetime is hyperbolic.  Why?  Because time is imaginary.

From the Wikipedia article on the spacetime interval:

There are two sign conventions in use in the relativity literature:

and



Let us take the second convention and rewrite it to a more standard hyperbolic form:

    s2 = x2 + y2 + z2 – (ct)2

But, since time is imaginary, we can rewrite this to the Euclidean (Pythagorean theorem) form:  
    s2 = x2 + y2 + z2 + (cti)2


The result is the same.  The addition of i (the imaginary number, square root of -1), when squared, reverses the sign of the time component.  But this formulation shows exactly what is going on in this distance equation.  The Pythagorean theorem holds in space as well as spacetime, but spacetime is hyperbolic because time is imaginary.

There are no inconsistencies, there are no contradictions.  Every concept is simple, even if the math is complex.  It even helps show that time is at 90 degrees to every space dimension, because the imaginary number line lies at 90 degrees to the real number line.

QED

Saturday, October 21, 2023

The Army needs this now.

The Army needs this now.  They don't need to study it for ten years, then spend ten years changing design specs, driving up the price before inevitably cancelling the program because the right palms didn't get greased.  Just buy a few thousand of the things, and issue them out two per maneuver company, 4 per battalion.

The Finns have had these for 15 years.  The Russians have had something similar for 50 years.  Our perfumed princes are just now "beginning to prepare to form a working group to write a white paper on the issue."




The Finnish Patria NEMO 120mm gun-mortar.  The system is really the turret, it's shown here integrated into a wheeled vehicle.  They can also put it on a tracked vehicle, a shipping container, or even a boat.

"Patria NEMO is a turreted, remote-controlled 120 mm mortar system for the needs of modern warfare and crisis management, which calls for mobility, protection, and accuracy. It is an indirect fire support system, but due to its direct fire capability, it can also be used for self-defence."

Elevation−3° to +85°
Traverse360°
Rate of fire10 rounds/minute (max); 6 rounds/minute (sustained)

We need more indirect firepower than we have.  And it needs to be on call at the lowest possible level.  And we need assault guns to take out bunkers and concrete buildings.  

The NEMO can operate in urban terrain, placing 120mm mortar shells into the windows of a building, then dropping indirect fire on the intersection behind the building, then using direct fire to destroy an onrushing car bomb (VBIED).

The only thing it's missing is a machine gun.  But that's a problem that should be fairly easy to rectify.


Wednesday, October 4, 2023

New Monster Hunter: Memoirs novel!

Available now:  Monster Hunter memoirs:  Fever

Bought it yesterday morning.  Finished it yesterday afternoon.  Does it need more praise?


Friday, September 29, 2023

Cedar Sanderson's The Groundskeeper

 I've enjoyed everything Cedar has written so far.  If you're here, you probably will, too.  Give it a read.  You won't regret it.



Friday, September 15, 2023

Surprise Unexpected Enlightenment!

New Rachel Griffin book!

The long awaited sixth book of Unexpected Enlightenment has arrived in time for the anniversary of Rachel's arrival at the Roanoke Academy for the Sorcerous Arts.

CEO group think

 It's like these CEOs all know each other and share the same culture of stupidity and shamelessness.

The Unity video game engine has decreed that come January 1st, all games made with their engine will have a new contract enforced retroactively, and that the developers will owe Unity a fee for every download (ever) of any game made with their engine.

The current CEO of Unity is the former CEO of Electronic Arts, who was fired for running EA into the dirt at the time.  He's a graduate of Berzerkeley school of business, and apparently has a long history of being promoted from failure to failure.

As George Carlin said, "It's a big club, and you ain't in it."

Friday, September 1, 2023

Simple D&D melee stunts

House rule for simple melee combat stunts in a D20 system. After making the attack roll:

Succeed: Disadvantaged damage and stunt, or normal damage.
Succeed by 5: Normal damage and stunt, or advantaged damage. Succeed by 10 (crit): Advantaged damage and stunt, or doubled damage.
Fail: No effect. Fail by 5: Take disadvantaged damage from opponent. Fail by 10 (fumble): Take normal damage from opponent. Bosses (and PCs) could deal disadvantaged damage and a stunt instead.

Advantaged roll: Roll two dice, take the better. Disadvantaged roll: Roll two dice, take the worse.


Bonus idea: armor damage reduction

If you want armor to reduce damage instead of (or in addition to) making the target harder to hit, do not use a static number for the armor. Roll for it, just like for the weapon damage. Shields add an extra armor roll. (Shields should be more useful in games than they usually are.)

Option 1 (math, less deadly): Subtract the armor roll from the weapon roll. If the armor equals or exceeds the weapon, no damage is taken.

Option 2 (no math, more deadly): Compare the rolls. If the weapon roll is higher, the target takes the damage.

If you really want to get crunchy with this, you could add skill dice to either or both sides of the combat. Add terrain and range dice for defending against a ranged attack. Use your imagination. You could even use this system in place of making separate attack and damage rolls. (h/t: Into The Odd)

Sunday, August 27, 2023

Why Listack? A personal journey.

Why Listack?  By that, I mean, why did I go to the trouble of creating the language at all?

Easy answer - I'm a language geek.  I like languages, human and programming.  I collect programming language books, and read them for fun.

Harder answer - I'm bored.  This is something that is challenging me, and making me learn new things.  Mostly by trial and error, partly through reading books (Crafting Interpreters by Nystrom is great!) and watching videos.

I started learning Python a couple years ago to get back into programming.  I started programming when I was 12 and received a Commodore Vic-20 for Christmas.  I eventually saved up my pennies and bought a Commodore 64 on layaway.  a decade later (early 1990's), I went to college for "computer science", and was... disappointed with the education provided.  I worked for the university to make money (a bit above minimum wage), and ended up being one of the two student managers for the computer labs.  We supervised around 40 lab consultants, and reported to a full time staffer.  I dropped out of college (the second time, mind you) to join the Army (again).  I just lost interest at the beginning of my senior year.  Especially after I noticed that I was helping the grad students with their thesis projects.  Especially especially after finding out that the local programming jobs (mostly at Compuserve) paid a dollar more an hour than working at McDonalds.  So I quit, went to work for McDonalds for a year an a half, and finally got back into the Army.  (They don't like taking in retreads.  A retread is worth 1 point, where a new recruit is worth 8 to the recruiter.)

History - I bought a book on the Forth programming language from a library sale when I was a teenager for a quarter.  I've been interested in its simplicity ever since.  I read the book about the same time I got my first real calculator - an HP 11C, which I still have and use.  The old HP calculators work in Reverse Polish Notation:  instead of 2 + 3, you enter 2 3 +.  Just like Forth.  RPN = postfix notation = stack based language.

Despite its power and simplicity, Forth is what is called a "Write only" language.  It's easy to write programs in it.  It's terrible to go back to and debug later.

While I was playing around with the esoteric languages (thanks, Truttle1), I ran across False, a minimalist stack-based language.  I implemented it, and saw the power of the concept of quoted programs.  I then found Factor.  It advertised itself as  "... a concatenative, stack-based programming language with high-level features ..."  From there I found Joy, the concatenative (AKA stack based, AKA postfix) language that drew the most academic attention, because it was created (and advertised) by a full Professor who had the mathematical logic to justify it.  (Do check out his papers.  They're quite readable, which is unusual for functional languages and combinatory theory.)

The power of functional programming laid bare in its most essential, simplified, true form is astonishing.  But it's not easy to read, unless this like reading enjoy you.

And then it occurred to me:  words (functions) are just tokens in a list.  Lists can be rearranged!  All I needed was a coherent naming convention and a means to tell whether and how far to move the tokens.  Words can be rearranged, but get executed serially, first come, first served.  When Listack encounters a word, it checks to "fix", and moves the word around if necessary.  (Words are executed serially, one after the other, with no priorities other than 'first come, first served'.)  And thus, slowly, Listack is taking shape.

How is Listack different from the horde of other stack based languages? 
Universal Function Call Syntax.
The four functional word forms:

Postfix:                                          .word            after all arguments
Infix:                                               word            after first argument
Prefix:                                             word:           before all arguments
Callable:                                         word()          before parens around arguments
Immediate:                                     word             after arguments

You can use any of these with most function words.  They won't have much effect on Immediate words, of course, because Immediate and Postfix are how everything actually works.  But you can type in your program in the style you find most suitable.  They all work, with just a little effort on the programmer's part.

These are all the same program:

+: 1 2 if: {=: 3} {println: "True!"}{println: "False"}
1 + 2 = 3 if {"True" println} else {"False" println}        # else is semantic sugar
1 2 .+ 3 .= {"True".println} {"False".println} .if            # This is how it actually executes.
+(1, 2) if(=(3) then {println("True")} else {println("False")})    # then is also semantic sugar

But it could also be written as:

if: (1 + 2 = 3) then {println("True")} else {"False".println}

The point is, you, the programmer, get to decide how you want your program to look.  They all work the same, because words are just tokens in a list that are executed serially.


Monday, July 31, 2023

How should we train men to be military officers?

    The service academies are now a national joke.  They teach very little aside from arrogance and woke Leftism.  They should teach future military officers to be leaders and thinkers.  How could we better go about this task?  What value does a 4 year degree, in this age of reduced (or eliminated) standards, bring to military leadership?  Remember, the ultimate purpose of officers is to lead men into battle and win wars.

    I like Heinlein's idea.  No man shall be eligible for officer training until after he has honorably served no less than two years nor more than ten as an enlisted man.  This weeds out a lot of undesirable candidates.  If you are unwilling to serve amongst the lowest of the low, to put up with the dirty end of the stick, you aren't what we need or want to lead troops into battle.  We also only want patriots.  Anti-American types need not apply.

    After two years enlisted duty, a young man may apply to officer candidate school.  I envision this school as lasting at least six months, at most two years.  The topics taught shall be leadership, psychology, advanced first aid and field hygiene, military history, geography (both physical and human), effective communications (oral and written), basic accounting, technology (heavy on the practical, light on the theoretical), tactics, logistics, military operations, and basic staff work.  Practical courses shall include rigorous physical training (daily), weapons handling (daily), marksmanship (monthly), a martial arts discipline (weekly), close combat (weekly, using airsoft guns), drone use (weekly), wargaming (weekly, starting with miniatures, eventually moving on to board games, and finally computerized staff games).  One week per month shall be spent training in the field or onboard ship.

    Graduation is to be conditional upon successful completion of all courses and activities, honorable and moral conduct throughout, as well as acceptable conduct during a six week final exercise in the field or onboard ship.  Upon graduation, these young men will be commissioned as junior officers, with a service obligation of six years.

    What about doctors and nurses?  They do not lead troops into combat, so they don't get to be officers.  Doctors could be Warrant officers, but honestly, most of them should just be DoD civilians under long term contracts.

    Those are my thoughts on the topic.  What are yours?

Friday, July 28, 2023

FRPG alternate rules

 Abstract wealth:

Wealth is measured in abstract coinage. If you want to buy something, you compare its price with your coinage. If the price equals your coinage, you buy it and lose a coin. If the price is one less, you buy it and lose a coin one third of the time. If the price is two or more coins less, you just buy it. You can't afford anything that costs more coins than you have.

Adding treasure works similarly. Anything worth less than one coin than you have doesn't add to your wealth. One coin less will add to your coinage one chance in six. Treasure equal to your coinage increases it half the time.  Treasure one coin higher than your current wealth is increased one chance in six.

When using slot based encumbrance, your coinage occupies 1/2/3/5/10 slots. When using pounds, your coinage weighs 1/3/10/30/100 pounds. More than that and you need a wagon or magical container.


Alternate spellcasting
Slots and checks in a d20 system.
(Spells have tiers instead of levels to avoid confusion.)
Use the spells per day charts. Casting those spells doesn't require a check, but does use the slots. Daily renewal of spell slots requires a minimum of 6 hours of sleep plus one hour of spellbook study or prayer.
To cast additional spells, the caster makes a spellcasting check at
DC 10 + twice the spell tier. Their casting bonus is their spellcasting level plus stat bonus.
If a caster fails a spellcasting roll by 5 or more, they cannot attempt to cast that spell again until after a full turn of uninterrupted spellbook study or prayer. If they fail by 10 or more, they can't attempt spellcasting checks of spells of that tier or higher until after an uninterrupted hour of spellbook study or prayer.
If a caster makes a roll by 10 or more, something good happens. Examples: Spell is upcast, damage/healing is rolled with advantage/maximized/doubled, spells affects triple the usual targets, spell duration is tripled, area of effect is doubled, allies/enemies in AOE are ignored, caster gets to choose instead of rolling on a random chart, caster regains a used spell slot of that tier or higher, caster heals the spell's tier in hit points...
Cantrips are tier 0 spells. Cantrip checks are made with advantage once the caster gains a tier 2 spell slot. Read Magic is a cantrip.
Caster can attempt to cast a known spell of one tier higher than their chart says they can, but the check is made with disadvantage. Failure by 5 results in the loss of half the spell's tier in hit points.  Failure by 10 results in the loss of the spell's tier in hit points.  These are in addition to the usual penalties.
To upcast a spell (when allowed), either use a higher tier slot, two equal slots, a slot and two of the next lower slots, a slot and a check, or disadvantage on the check.
Turn Undead is a cleric spell-like ability, where the DC is 10 + twice the target's hit dice. For every point the check exceeds the DC, one additional creature (of that DC or lower) is turned. Succeeding by 10 destroys the target, with an additional creature destroyed for every point higher. Failing by 5 or more results in the cleric not being able to attempt to turn that creature again until after an uninterrupted turn of prayer. Failing by 10 results in the cleric not being able to turn any creatures of that power or higher until after an uninterrupted hour of prayer.

Wednesday, July 26, 2023

Referencing and Dereferencing in Nim



Here is an executable guide to how referencing and dereferencing work in Nim. I made this to understand it myself, because there is no explanation in the online manual or either book on Nim.

******************


type
refInt = ref int
var
a: int = 1
b: refInt
c: refInt
d: refInt


# UPDATE
# Use this template to make referencing much easier!

template `-->` [T](receiver: ref T, target: T)=
receiver = cast[ref type(target)](target.addr)

echo a
echo "a ", a.addr.repr
# Sadly, the Nim 2.0.0 update removed the physical addresses from repr
new(b)
b[] = a
echo b[]
echo "b ", b.addr.repr
a = 2
echo a
echo "a ", a.addr.repr
echo b[]
b = cast[ref int](alloc0(sizeOf(a))) # primitive, use new(b) instead
b[] = a
echo b[]
echo "b ", b.addr.repr
a = 3
echo a
echo b[]
b = cast[ref int](a.addr) # this works!
echo b[]
new(c)
c = b
echo "c ", c[]
a = 4
echo "a ", a
echo b[]
echo c[]
echo type(c)
echo "a ", a.addr.repr
echo "b ", b.addr.repr
echo "c ", c.addr.repr
echo ""

var x: array[5, int]
type ArrRef = ref array[5, int]
var y, z : ArrRef
x = [1, 2, 3, 4, 5]
y = cast[ArrRef](x.addr)
# addr provides a ptr type
# cast to convert ptr to ref
z = y
echo "x ", x, " is ", x.addr.repr
# repr is a lower-level version of the $ to-string operator
echo "y ", y[], " is ", y.addr.repr
# [] is dereference, so c[] --> b
echo "z ", z[], " is ", z.addr.repr
echo ""
z[4] = 10
echo "x ", x, " is ", x.addr.repr
echo "y ", y[], " is ", y.addr.repr
echo "z ", z[], " is ", z.addr.repr
new(z)
# use new() to allocate space for the value to be referenced
z[] = x
z[4] = 20
echo ""
echo "x ", x, " is ", x.addr.repr
echo "y ", y[], " is ", y.addr.repr
echo "z ", z[], " is ", z.addr.repr
# only z is now [1, 2, 3, 4, 20]

var q: ArrRef
q --> x



Friday, June 16, 2023

Why gravity is different

Gravity seems to act like a force, but has been shown to not be like the other forces.  It's different.

How?  Why?

Prerequisite knowledge:  Both momentum (mass times velocity) and kinetic energy (half mass times velocity squared) are conserved properties.

Forces act with energy.  They use energy to change things.  Two balls hitting each other exchange kinetic energy, thus altering their momentum.

Gravity directly affects a ball's momentum, thus altering its kinetic energy.  Gravity doesn't use energy to achieve its effects.

It's that simple.


Not quite so simple:  There are both objective and subjective time and, thus, velocity.  Objective time ticks along, moving things a certain distance in a certain time.  This is objective momentum, and is how photons move and change over time.  Subjective time ticks along faster or slower, stretching or shrinking perceived space along with itself.  This is subjective momentum (kinetic energy), and is how matter moves.  Photons don't have subjective time.

If momentum and kinetic energy are conserved, where do they come from when gravity accelerates something?  Space-time itself.  Space-time is a field of potential energy, from which all other fields and effects withdraw their energy.  In other words, kinetic energy + potential energy = constant, at every point.

Space-time is the field which governs motion, involving both time and distance.

Sunday, June 11, 2023

Thursday, June 8, 2023

Listack v0.4.0 is live

 I have spent the last few months creating and refining my own new computer language:  Listack.  Originally written in Python, I spent the last two months rewriting it in Nim, so it is now much, much faster.  What is Listack?  Besides a portmanteau of List and Stack, of course.

Listack is a concatenative, stack-based language inspired by Factor and False, among others.  It is interpreted.  It is flat - all functions are in-line functions.  Like all concatenative languages, it encourages the use of "higher" functions (called words) from "functional programming".  Listack has the concept of good/bad data baked into its core.  It has a very basic type system, but user created objects can use user-created types of arbitrary complexity.  

It is polymorphic with limited arity, meaning each command always uses the same number of arguments but the types of those arguments can differ through redefinitions of the word.  For example, '+' is used for both numbers and strings.  1 + 2 --> 3, where "abc" + "def" --> "abcdef".

The main problem with stack-based languages is that their syntax is weird.  Every command word depends on the data it needs to work upon already being on the stack, waiting for it.  This is postfix form:  1 2 +, instead of the more usual 1+ 2 or even + 1 2.  Listack gets around this by employing uniform function call syntax.  Every word except immediate ones can go in front of, between , or after its arguments.  The following are all equivalent in Listack:
+: 1 2        prefix form - before all arguments
1 + 2        infix form - after first argument
1 2 .+        postfix form - after all arguments
+(1, 2)        callable form - immediately before parenthesis surrounding all arguments

You can, to a degree, pick and choose how you want your program to look and feel.  Just keep in mind that every word actually executes in postfix form.  (Immediate words are essentially postfix without the leading period.)  Oh, and the commas are just syntactic sugar.  The parser converts them to spaces when they're not inside a quote.  The following snippets all add 1 to 2 and then multiply the result by 3.
1 2 .+ 3 .*
1 + 2 * 3
(1 + 2) * 3
*: (+: 1,  2) 3
(+: 1 2) 3 .*
*(+(1, 2) 3)
2.inc * 3

The following doubles and also squares a list of numbers to produce 6 10 20 9 25 100.
[3 5 10] {dup .+} {dup .*} bi_apply

This does a similar thing but compiles the numbers into lists [6 10 20] [9 25 100]
[3 5 10] {{dup .+} .map} keep {dup .*} .map


Listack has an interactive REPL.  After you compile it (nim c -d:release listack.nim), execute it by typing: 
./listack

You can run a program file as follows:
./listack filename
with options for -debug and -verbose

Don't have Nim?  Check out their website.

Wednesday, May 31, 2023

New Nathan Lowell Solar Clipper book available!

 Nathan Lowe''s newest "Solar Clipper" series book is now available!

Read the continuing adventures of "Call me Ishmael" and Pip.  Now available from Amazon.

School Days


Cover image from Amazon.com

Saturday, May 6, 2023

Knave 2.0

  The kickstarter is on for Knave 2.0!

  If you don't recognize it, Knave is the work of Ben Milton (of the Youtube channel Questing Beast) .  The original Knave, along with his Maze Rats, is an all-time best seller at Drive-Thru RPG.  Knave distills the adventuring rules of D&D down to their bare essence in a very playable manner in just a few information-rich (yet readable) pages.  The rest of the small booklet is enough random tables to run a game with, especially when combined with the massive random tables in Maze Rats.

  Knave 2.0 expands on the idea in deluxe printed (or pdf) form, with a LOT more tables.

  My favorite of the 100 random spells is Catherine:  You summon an attractive young woman who will answer questions and help the party with a few non-dangerous tasks if asked politely.



Even if you're not interested in backing the project, if you like role playing games, check out his Glatisant newsletter.  It's a free monthly roundup of the best of the internet musings on fantasy & sci-fi role playing.

Monday, April 17, 2023

The most important news you'll hear all week

This is the most important thing you'll hear all week. I don't care if Russia captures Kiev and hangs Zelenskiy by his toes, this is more important.

"there are a couple of bidders out there who are willing to bet very big money that food and fuel prices will triple ($18/$6.5) in nominal prices in the near term (i.e. five year horizon)." 


The real (not government "adjusted") rate of inflation for 2022 was in the range of 25-30%.

$100 compounded quarterly at 10% interest for 5 years is: $163.86
$100 compounded quarterly at 15% interest for 5 years is: $208.82
$100 compounded quarterly at 20% interest for 5 years is: $265.33
$100 compounded quarterly at 25% interest for 5 years is: $336.19

$100 compounded quarterly at 30% interest for 5 years is: $424.79
$100 compounded quarterly at 35% interest for 5 years is: $535.29

Tuesday, April 4, 2023

Archimedes wind turbine

This brochure for the Archimedes wind turbine looks pretty cool.  Until you read it, that is.


picture from the web site

Unfortunately, at normal ground-level wind speeds (5-10mph), it produces negligible power (well under 10% rated). It starts being effective (near 50% rated power) with 20mph winds, but is only rated for 28mph (100/550 watts), and then cuts out at 31mph (140/780 watts).

That's a very narrow window of effectiveness to produce, at best, a few score (small) / hundred (large) watts of power.  It doesn't help that the brochure is self-contradictory in places.  Do they need a better editor, or better (more consistent) facts?

On the other hand, how many could you fit on the average rooftop?  The big one is five feet across, 6¼ feet long, and weighs 620 pounds.  The little one is 2.5' x 3.6' and weighs a 'mere' 135 pounds, but only produces about one-fifth the power.