Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs for Qi 4 #146

Merged

Conversation

countvajhula
Copy link
Collaborator

Summary of Changes

WIP docs.

Public Domain Dedication

  • In contributing, I relinquish any copyright claims on my contribution and freely release it into the public domain in the simple hope that it will provide value.

(Why: The freely released, copyright-free work in this repository represents an investment in a better way of doing things called attribution-based economics. Attribution-based economics is based on the simple idea that we gain more by giving more, not by holding on to things that, truly, we could only create because we, in our turn, received from others. As it turns out, an economic system based on attribution -- where those who give more are more empowered -- is significantly more efficient than capitalism while also being stable and fair (unlike capitalism, on both counts), giving it transformative power to elevate the human condition and address the problems that face us today along with a host of others that have been intractable since the beginning. You can help make this a reality by releasing your work in the same way -- freely into the public domain in the simple hope of providing value. Learn more about attribution-based economics at drym.org, tell your friends, do your part.)

@countvajhula countvajhula changed the title Update docs for qi4 Update docs for Qi 4 Jan 5, 2024
qi-doc/scribblings/interface.scrbl Outdated Show resolved Hide resolved
qi-doc/scribblings/field-guide.scrbl Show resolved Hide resolved
qi-doc/scribblings/forms.scrbl Show resolved Hide resolved
qi-doc/scribblings/qi.scrbl Outdated Show resolved Hide resolved
@countvajhula countvajhula marked this pull request as ready for review January 12, 2024 10:36

@codeblock{(~> 5 (as v) (gen v))}

... produces @racket[5].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a real ellipsis character (C-k ,. in Vim, or Alt-; on macOS). You could also repunctuate the sentence as

This example
@codeblock{…}
produces @racket[5].

Or use an examples form?


In general, bindings are scoped to the @emph{outermost} threading form (as the first example above shows), and may be referenced downstream. We will use @racket[(gen v)] as an example of a flow referencing a binding, to illustrate variable scope.

@codeblock{(~> 5 (as v) (gen v))}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be (~> (5)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These code samples are in Qi context rather than Racket context.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps that should be clearer? It reads like a common syntax error, and I worry about the possible confusion there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I think using flow context is also what makes using something like examples harder, so I'd encourage revising that decision even if it ends up dragging in "incidental" Racket stuff.)

Comment on lines +859 to +865
@codeblock{(if (~> ... (as v) ...) (gen v) (gen v))}

Analogously, in a @racket[switch], variables bound in each condition bind the corresponding consequent flow.

@codeblock{(switch [(~> ... (as v) ...) (gen v)]
[(~> ... (as v) ...) (gen v)])}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-elided examples would probably be more helpful here.

@@ -29,6 +29,10 @@ Decompose your @tech{flow} into its smallest components, and name each so that t

A journeyman of one's craft -- a woodworker, electrician, or a plumber, say -- always goes to work with a trusty toolbox that contains the tools of the trade, some perhaps even of their own design. An electrician, for instance, may have a voltage tester, a multimeter, and a continuity tester in her toolbox. Although these are "debugging" tools, they aren't just for identifying bugs -- by providing rapid feedback, they enable her to explore and find creative solutions quickly and reliably. It's the same with Qi. Learn to use the @seclink["Debugging"]{debugging tools}, and use them often.

@subsection{Be Intentional About Effects}

Qi encourages a style that avoids "accidental" effects. A flow should either be pure (that is, it should be free of "side effects" such as printing to the screen or writing to a file), or its entire purpose should be to fulfill a side effect. It is considered inadvisable to have a function with sane inputs and outputs (resembling a pure function) that also performs a side effect. It would be better to decouple the effect from the rest of your function (@seclink["Use_Small_Building_Blocks"]{splitting it into smaller functions}, as necessary) and perform the effect explicitly via the @racket[effect] form, or otherwise escape from Qi using something like @racket[esc] (note that @seclink["Identifiers"]{function identifiers} used in a flow context are implicitly @racket[esc]aped) in order to perform the effect. This will ensure that there are no surprises with regard to @seclink["Order_of_Effects"]{order of effects}.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps don't quote "side effects"?

A short example of what this paragraph says would be useful.


Consider the Racket expression: @racket[(map sqr (filter odd? (list 1 2 3 4 5)))]. As this invokes @racket[odd?] on all of the elements of the input list, followed by @racket[sqr] on all of the elements of the intermediate list, if we imagine that @racket[odd?] and @racket[sqr] print their inputs as a side effect before producing their results, then executing this program would print the numbers in the sequence @racket[1,2,3,4,5,1,3,5].

The equivalent Qi flow is @racket[(~> ((list 1 2 3 4 5)) (filter odd?) (map sqr))]. As this sequence is @seclink["Don_t_Stop_Me_Now"]{"deforested" by Qi's compiler} to avoid multiple passes over the data and the memory overhead of intermediate representations, it invokes the functions in sequence @emph{on each element} rather than @emph{on all of the elements of each list in turn}. The printed sequence with Qi would be @racket[1,1,2,3,3,4,5,5].
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should quote "deforested" either.

@@ -350,6 +354,18 @@ Worse still, even though this computation raises an error, we find that the orig

So in general, use mutable values with caution. Such values can be useful as side effects, for instance to capture some idea of statefulness, perhaps keeping track of the number of times a @tech{flow} was invoked. But they should generally not be used as inputs to a flow, especially if they are to be mutated.

@subsection{Order of Effects}

Qi flows may exhibit a different order of effects (in the functional programming sense) than equivalent Racket functions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…unless those effects are marked with effect or esc, in which case the order is supposed to be guaranteed, right?

@countvajhula countvajhula merged commit 64976db into drym-org:lets-write-a-qi-compiler Jan 12, 2024
5 of 6 checks passed
@countvajhula countvajhula mentioned this pull request Jan 15, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants