Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As far as I can tell, <code>primitiveBindings</code> is <em>not</em> a global environment, but rather an action that, when performed, generates a fresh mapping with the primitive bindings already set up. Perhaps a better name for it would have been <code>createPrimitiveBindings</code>. There is no way to have proper globals in Haskell without <code>unsafePerformIO</code> hacks. </p> <p>Therefore, the way you're trying to add <code>eval</code> would make it evaluate everything in a <em>new</em> environment, since you're re-running the <code>primitiveBindings</code> action. We can easily take care of the type errors, if that is indeed what you intended:</p> <pre><code>baseFun :: [(String, [LispVal] -&gt; IOThrowsError LispVal)] baseFun = [("eval", evalInNewEnv)] where evalInNewEnv args = do env &lt;- liftIO primitiveBindings unaryOp (eval env) args </code></pre> <p>As you see, there is no need for any <code>readIORef</code> here, since <code>eval</code> already expects <code>Env</code> which just a type synonym for an <code>IORef</code>.</p> <p>However, it sounds to me like you'd like <code>eval</code> to work in a "global" environment, in which case, you would need to have this environment passed to you somehow, since as I mentioned, there are no globals. For example, we can define something like this which would create a new environment with <code>eval</code> in it. </p> <pre><code>primitiveBindingsWithEval :: IO Env primitiveBindingsWithEval = do env &lt;- primitiveBindings bindVars env [("eval", unaryOp (eval env))] </code></pre> <p>You can then replace existing uses of <code>primitiveBindings</code> with <code>primitiveBindingsWithEval</code> when you want a fresh environment with <code>eval</code> in it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload