# Qi tutorial and Jay's challenge

**URL:** <https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162>\
**Category:** Show & Tell\
**Tags:** racketcon\
**Created:** [November 20, 2021, 12:28am UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162 "2021-11-20T00:28:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)\
**Post date:** [November 20, 2021, 12:28am UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162/1 "2021-11-20T00:28:58Z")

</div>

Hey all,

Following up from RacketCon, based on some feedback (esp. from Jesse Alama and William Hatch) I've created a tutorial for Qi that includes lots of illustrative examples.

[https://docs.racket-lang.org/qi/Tutorial.html](https://docs.racket-lang.org/qi/Tutorial.html)

At RacketCon, in the Q&A, Jay pointed out that the SICP eval example I used in my slides only converted the _expression_ to be evaluated into a flow, while leaving the _environment_ alone even though it had a lot of redundant mentions in the body of the function. He posed a challenge to incorporate the environment into the flow too in an elegant way.

Well, I'm pleased to report that I've added an implementation using flows exclusively, incorporating both the expression as well as the environment. Doing this in "an elegant way" required adding a new, intuitive, feature to the switch conditional form. See for yourself at the tutorial linked above whether you think this fully fluid implementation is the best one or not -- it's one of the examples used.

Enjoy, and happy Friday! 🍻

-Sid

---

<div class="post-metadata">

**Author:** ![scolobb](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/scolobb/32/108_2.png) [@scolobb](https://racket.discourse.group/u/scolobb)\
**Post date:** [November 20, 2021, 1:16pm UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162/2 "2021-11-20T13:16:53Z")

</div>

Very interesting, thank you for the announcement! When I was a Haskeller in my previous life, I enjoyed the point-free style, which consists precisely in chaining transformations and avoiding explicit mentions of the argument. The Qi package seems to do this, and way more. Exciting!

As a former Haskeller, I can't help but ask the following question: Is there Typed Qi? Is there a project to make Typed Qi?

---

<div class="post-metadata">

**Author:** ![jeapostrophe](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jeapostrophe/32/10_2.png) [@jeapostrophe](https://racket.discourse.group/u/jeapostrophe)\
**Post date:** [November 20, 2021, 3:23pm UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162/3 "2021-11-20T15:23:42Z")

</div>

Cool! Glad to help.

Is it uglier if you change it from `Expr -> Env -> Val` to `(Expr x Env) -> Val` and put a bunch of `car` and `cdr` in the code?

---

<div class="post-metadata">

**Author:** ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)\
**Post date:** [November 20, 2021, 6:15pm UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162/4 "2021-11-20T18:15:44Z")

</div>

Typed Qi sounds like a very fun / interesting project. I don't have a lot of experience with type systems so I don't have much insight to add here, but at arm's length, I think the same considerations would apply to Typed Qi as typed anything - viz. we'd trade flexibility for robustness. E.g. right now flows always accept any number of arguments and fail at runtime if the arity doesn't match what the flow expects. And also, using flows in place of lambdas is a common pattern, like `(map (☯ (~> sqr add1)) (range 10))`. These would be less convenient if we had to type them, although of course there is a huge upside as well.

But yeah, there isn't already a project underway @scolobb . I'm happy to start something up here if there is community interest!

---

<div class="post-metadata">

**Author:** ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)\
**Post date:** [November 20, 2021, 6:25pm UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162/5 "2021-11-20T18:25:58Z")

</div>

@jeapostrophe yeah, initially I tried implementing it with `switch` where both conditions and consequents receive all inputs. In this solution I had to use `1>` in all of the predicates, which is essentially `car` in the `(expr x env)` case. The third solution in the tutorial is strictly prettier than this one, since it retains the same consequent expressions and also loses the `car` references in the predicate expressions. Thank you for inspiring it 😝

---

<div class="post-metadata">

**Author:** ![Dexter](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dexter/32/1432_2.png) [@Dexter](https://racket.discourse.group/u/Dexter)\
**Post date:** [November 23, 2021, 8:19am UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162/6 "2021-11-23T08:19:44Z")

</div>

Hey I'm getting an ugly uncaught exception error opening the Qi tutorial link:

### Page not found

> ([(uncaught-exception-handler)](https://docs.racket-lang.org/) (_(+(_)(_(+(_)(_)(_)(_)(_))(+(_)(_)(_)(_)(_))(+(_)(_)(_)(_))))(+(_)(_)(_)(\*)))) uncaught exception: 404

Cheers

---

<div class="post-metadata">

**Author:** ![spdegabrielle](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/spdegabrielle/32/95_2.png) [@spdegabrielle](https://racket.discourse.group/u/spdegabrielle)\
**Post date:** [November 23, 2021, 9:38am UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162/7 "2021-11-23T09:38:56Z")

</div>

Hi Dexter,  
The build failed on the package server.  
We are looking into it and will get back to you.  
Best wishes  
Stephen

[https://pkgs.racket-lang.org/package/qi](https://pkgs.racket-lang.org/package/qi)

---

<div class="post-metadata">

**Author:** ![spdegabrielle](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/spdegabrielle/32/95_2.png) [@spdegabrielle](https://racket.discourse.group/u/spdegabrielle)\
**Post date:** [November 23, 2021, 5:22pm UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162/8 "2021-11-23T17:22:28Z")

</div>

@Dexter looks good now. Cc @countvajhula

---

<div class="post-metadata">

**Author:** ![countvajhula](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/countvajhula/32/65_2.png) [@countvajhula](https://racket.discourse.group/u/countvajhula)\
**Post date:** [November 23, 2021, 6:42pm UTC](https://racket.discourse.group/t/qi-tutorial-and-jays-challenge/162/9 "2021-11-23T18:42:45Z")

</div>

@Dexter thanks for the heads up! I merged a PR to do a big change in the package structure of the project (to using the lib/test/doc structure that many other projects use), and the package server didn't like it. I [reverted](https://github.com/countvajhula/qi/pull/11) the changes last night so it should be back to normal now. Let me know if you continue to encounter issues. I'll probably make another attempt at merging the changes soon, so just a heads up that there might be more hiccups, but hopefully not.
