Fizzbuzz and complex filtering

You have a remarkable brain that still exists :smiley: .

Just FYI, slightly OT, but I think worth the words, the “Monad” has a long history before computing since the older philosophical concepts very much informed more modern computing ideas of it.

The Monad goes back, way, way back. Likely the greatest philosophy pundit of it was Leibniz in The Monadology.

The essential idea of monads, in philosophy, is they are self-referential wholes since they are existence. The lingo is not so easy. More crudely expressed they are “undivided multiplicities”. That is not the conundrum it sounds like since they are self-creating.

Back on earth, regarding TW, its fundamental Quine nature very much participates in a Monad Mode.

The lingo about monads in computer science is a bit of a mixed bag, though there have been various good forays into it that mostly attend “functional programming”.

Just a comment, dear leader.
TT

1 Like

FYI, here is a TiddlyWiki javascript macro implementation of forth My TiddlyWiki — a non-linear personal web notebook

The entire implementation is a single javascript tiddler.

It is a macro which takes the forth program as an input argument and returns the top of the stack after executing the forth program.

Your example:

<<mforth "6 15 8 swap - *">>

→ -42

Pop a string from the stack and run it as a filter:

<<mforth """
' [range[5]] ' filtertiddlers
""">>

→ 1,2,3,4,5

Access a tiddlywiki variable by prefixing a word with $:

<$let myvar="myvalue">
<<mforth " $myvar ">>
</$let>

→ myvalue

You could probably convert that code into a filter operator pretty easily. Like you suggested in your example, treat the input as the initial stack and use the parameter as the forth program.

2 Likes

We asked for a banana…

      run(...calc) {
        var tokens;
        tokens = this.tokenize(calc.join(" "));
        this.parse(tokens);
        this.interpret();
        if (this.stack.length === 0) {
          this.stack.push("no result");
        }
        return String(this.stack.pop());
      }

And that, ladies and gentlemen, as I’m sure the late great Joe Armstrong would agree, is a banana.

:banana:

kudos @btheado (I’m assuming that’s your code?)

No, not mine. I came across the link in the google groups. Quaraman/Sven is the author. Not sure if Quaraman is still active here.

Kyle Simpson’s (@getify’s) deep dive…

You didn’t invent the monad. But the profound Quine nature of TW is certainly an instance of it. At base “the monad” is a philosophical concept of a self-generative whole that is an “undivided multiplicity”. In philosophy the term has greatest traction in Leibniz, though Spinoza also went into it, though he called it “modes”.

Just a comment
TT

@TiddlyTweeter Could you submit us a tw quine (in tw macro or filter or a combination of both? No js excepted for coding a filter op or a widget.

I’d be keen to see one!

I know it is hard to grasp. But ALL normal, self-saving TW’s ARE Quines. By design! That is it’s beauty & power!

TBH, for some years I been trying to get more attention to this fundamental aspect of TW.
I think it is important to flag, but I found most developers either didn’t grasp it or are not interested.

Best wishes
TT

What are you calling a “self-saving TW” exactly? My TW are saved when I press a dedicated button, exceped for server mode wikis which are autosaving. But I’m not sure this process save the TW code in full, and in fact, saves are one tiddler att a time, not as a whole.

I think what TT means is the nature of TW changing itself.

When you save a document in MS Word, you only save the document, you don’t change Word itself.

When you save a tiddler, you can, and often do, change TW itself.

@CodaCoder TW may behave in a way similar to a quine, but a quine must not read any input to replicate and neither use any command line arguments (this is only OK for multi-quines). And a quine dos nothing but replicate itself (by outputting its code). So TW is not a real quine IMHO. And happily so!

But, honest, I would never has thought of it as an auto-replicant program!

And I’m not really seeing how this is so connected with functional programming. How do you see that?

1 Like

Exactly that the TW saves itself over itself. There are many ways to do that. Don’t play dumb with me. You know that :smiley:

The Quine nature of TW resides in its ability to save its changed self to itself .

Best, TT

@jypre most so called Quines found in the wild are minimalist or trivial quines. TiddlyWiki is not.

Let us assume the universal client the browser exists every where, think of it as the virtual machine that our tiddlywikis run in.

If you load a single file tiddlywiki you can make changes to it that save back to itself. You can change the underlying functionality, tweak or rebuild the User Interface using tiddlywiki, in fact you can use tiddlywiki to cloan wikis that make other wikis. All this can be done with tiddlywiki alone.

TiddlyWiki is what we should refer to as a “non-trivial Quine”. For example tiddlywiki can also;

  • Document itself within itself (self documenting)
  • From within tiddlywiki you can see/edit every byte that defines tiddlywiki.
  • Generate new and revised wikis
  • Provide a platform for many solutions which can also act as a quine
  • We can build tiddlywiki’s own Software Development Kit, in tiddlywiki (See innerwiki plugin as one example).
  • You can write code to write code in tiddlywiki

I am not surprised coders are bored with the concept of Quines because they rarely see anything but “trivial quines”.

However non-trivial Quines are meta recursive, ie not only can they build recursive self referential functions, but they can recursively reference themself in their totality, and even generate new cloans or instances of themself.

2 Likes

Bingo! :slight_smile:

Many thans @TW_Tones for your explanation. I think I’m enlighten now! Trivial quines had tainted the essence of a quine, that just seem be a toy for bored geeks. And you finally fail to realise what the true meaninq of //quine// is.

@TiddlyTweeter : this is why I didn’t see it, no jerking from me. Some stupidity may happen from time to time…

So a TW is a quine. But could a tiddler be quine by itself, that which would mean it would write its code to an other tiddler? I think it would need to create a random title for it or have a cycle of titles, for otherwise the process would not be able to keep going on forever.

Lastly, I still fail to see a strong connection between FP and quines.

1 Like

Yes. TW is intrinsically recursive.

You could overwrite another Tiddler with a boilerplate text, that would be dominance of one Tiddler over another. But TW is, at base, an equitable system. All tiddlers are equal–though some Tiddlers are macro-enhanced to be less equal than others.

Just a comment
TT

I still wonder wether tw is a real quine. I’m pretty sure it read its internal tiddlers to write itself. That would be a cheating quine, quite apart most other cheating quines.

I mean, if the text of tiddler A is “fubar”, a real quine would need to have somewhere some code writing “fubar” explicitely (see wikipedia article). I would be very surprised indeed if it was true.

@jypre I think it is demonstrably a non-trivial quine, however in contrast to many examples of quines it does have a user interface. Whilst you could design TiddlyWiki’s to launch, react to input or generate content, save and exit. We tend to give users the opportunity to participate in the wikis state or content. Of importance here tiddlywikis data is also code and code is also data all in tiddlers.

The simple example I can think of is a sophisticated Microsoft Word Document, these need Microsoft Word to be available to open, process, interact and save the document. Tiddlywiki (within a browser) is all we need to open, process, interact and save the tiddlywiki. But also to clone/generate other tiddlywikis. We can’t change Word beyond a few settings, only its documents.

There is an interesting talk from Douglas Crockford at 2012 what monads are (frist 30min) and about Concurrency (30min++) in JS … It’s very interesting, since he talks about constructions that we got with ES6 in 2015.

At WikiPedia Monad–functional programming is basically this:

… General-purpose languages use monads to abstract away boilerplate code needed for common operations (such as dealing with undefined values or fallible functions).

1 Like

Wikipedia says:

A quine is a computer program which takes no input and produces a copy of its own source code as its only output.

It depends on the perspective, how you see it.

  • Let’s say the browser is the environment, that can execute HTML source code
  • tiddlywiki.html is an HTML file – the source code.
  • The browser knows what to do with it.

So it’s possible to create a file-TW with only one purpose. To "Use no additional input and produce a copy of it’s own source code. … That’s exactly, what TW does if you press the “save-button”.

You may argue: “TiddlyWiki needs interaction to save itself!” … That’s right … But it’s simple to create a file based wiki that does save itself without any interaction."

Yes from the tiddler store, which is a variable. The mechanism is similar to constructive quines eg: Python quine:

exec(s:='print("exec(s:=%r)"%s)')

Where s is the variable that contains the template and 'print("exec(s:=%r)"%s)' is the template.

TW uses $:/core/templates/tiddlywiki5.html template to create itself.

Nope. See above.

Be surprised!

Most quines don’t make much sense. IMO that’s different with TW as Tony wrote. I would categorize it as: self replicating

Self-replication is any behavior of a dynamical system that yields construction of an identical or similar copy of itself.

eg: Similar copy of itself is the “Download Empty” button, which only uses a different template. There is no fullsize emtpy.html stored as a tiddler. It’s dynamically created.

2 Likes