bell lifted variables questions

Discussions, advice, bug reports and much more about the "bach" environment.
Post Reply
chrischandler
Posts: 8
Joined: Mon Oct 21, 2019 12:53 am

bell lifted variables questions

Post by chrischandler » Tue Jun 30, 2020 8:04 pm

In bell, I'm trying to call user functions within user functions. As I understand it, if I have a secondary user function being called within a primary user function then I need to lift the variable assigned to the secondary function at the start of the primary user function. Kind of a cumbersome way to state it, but I think that's correct. I've attached a patch where I am trying to do this, but calling the nested functions is causing a crash. I'm not sure if it's due to lifting the variable incorrectly or some other issue.

Any thoughts or direction would be very helpful. Thanks!

Code: Select all

----------begin_max5_patcher----------
1691.3oc6Z01aaaCD9yN+JtoF.aG33IJIKY2srWv1W5WWGv9PSW.sDcL6jnL
jnyKnn+22QRYK4XkXYWktzUGTXYch28v6gmNd7p+3IcrlldGK2BdM7NnSmOd
RmNZQJAcJtuiUB8tvXZtdXVgoIILgzZf4YR1cRs7amSk.eF7F3VpPBxTHjFG
CIKik7EwLX1RQnjmJxAtHmGw.JrLmksV9Oeo3RQNiAx4LHOQqaZDeFOjpdLf
VOlKXfiGb6bVlYbmlD5LasI.dtFTVzpYmRivzkB8TbTgPwxjzkxXlT6P1ERW
Pkgy4hquJiEJMDhKIXn8.vyUeww1QcIvanM79Bk3QZeOc5GNmDXUZetXk4IJ
Ye5jSTeL3yjh+SziWjwSnY2W5yZt.cbCcP+G1aYYbVNPEQvsbI5R.WhqJzDM
2fdHx74HqHhT1Yi0fB1CNcNMKAevP0ZxeMmI1vxpAkudL.za0p1zToLMAx3W
OWhSTVNS1W8.yDjBgYz74Za9qI3LJlOSplN2Py3zoXHRXZlh7iuWGK76oHV3
TeN8FlJbJJU6OPBqzQxPA5IQQLUx8kyqMitfKEf5uyg2RSTzXJhXBjFFtLK2
D2h.zi.CGNDNEWBWPyjbZbd+ZikH96avTvlwRD8EGxiDL42ZASB1snE2JVRB
Ssp0EHOw6CddpYMw22L4W84ZOvXF48KXFErlREWaUmCN941+lRCmODiAWvv2
CX2sP85vufyuaynK.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s.9DlF
2andaq15aGVtxFDOXjlcXqrES0HJ8PuTXsem5lgmBIp5IIa8yg2h8bhX2Z8b
J3qrdNEzNsbx+EbKmBZdGmF8+nFNE7kneSdGa2zw1M8MQ6lBZstM49huYSAO
K8Zx4qyVMEzNcZ5+nFMcr4PGaNzK1lCo524izkypnWztyAGaLzwFCcrwPGaL
zwFC8MYigzU2n+ER8feKg5h1Tx2rrv7zkYgqJJq32ECTViTDKWxE5e2eUFi5
+QP0fpsxylBz3l.jaK.TPC.xoEvwuINTKfih7I6.mfVBmuD7laCvwuEvwoA3
zFwajlPbpe1Ve9H0DpizFqQjlPdSZCfHMH5dbaAzWj7OMAnQagiIQNcwhhL+
ZPTPfmj+ClyAOdf9VtHsr+fV3Yh3qFu92YsEMCOstD2vYYl47t24a5HoUBdB
3LwRdQaDPmCgT2k.AEqcYA03G5lIbxmN4ewRr8kJ
-----------end_max5_patcher-----------

andreaagostini
Posts: 181
Joined: Fri Dec 03, 2010 1:51 pm

Re: bell lifted variables questions

Post by andreaagostini » Wed Jul 01, 2020 9:29 am

Hi,

I can't reproduce the crash. We've fixed various things in the bell engine, so I like to think that the bug you found is solved. But can you tell me your Max and OS versions? I'd like to investigate it more. Does it happen all the time, or only sporadically? Anyway, we plan to post very soon a new pre-release for our Patreon supporters, with all these fixes and a few new small features.

About lifting: yes, it's a complicated mechanism, I know. The way you lift the variable in the first example is perfectly correct syntactically. On the other hand, from a stylistic point of view the idea is that if you have function A that calls function B, and actually function B is only used from within function A (which is quite a typical case) then you can define B inside A and you don't need to lift it. On the other hand, if function B is also used from outside function A then perhaps its purpose is rather general and you might want to assign it to a global variable. Of course this is only a very generic guideline, but the idea is that function lifting is mostly necessary for recursion.

As for the second example, first of all mc2f (along with f2mc and a few others) is implemented as a built-in function in the pre-release we're about to post. Anyway, in your specific case yes, you need to lift both $harmser and $mc2f, which you do with ($lll -^ $harmser, $mc2f -> ...)

I hope this helps,
andrea

chrischandler
Posts: 8
Joined: Mon Oct 21, 2019 12:53 am

Re: bell lifted variables questions

Post by chrischandler » Wed Jul 01, 2020 8:06 pm

Hi Andrea,

Super helpful, thanks! I am on macOS 10.14.6 and Max 8.1.5. For this particular problem, the crash happens every time. If it's not crashing on your end then I'm at least happy to know that it's not something I am doing wrong.

That's a good idea about function B only being called within function A and not needing to lift it. I've tried two scenarios. In the attached patch, the left-hand example defines the $harmser function within the $makeSeries function ($makeSeries does not work properly, but no crashes), and in the right-hand example I've hardcoded $harmser so there is no function now but it still produces a crash.

At any rate, I look forward to the next pre-release you mention and bet what I'm experiencing is an already fixed bug.

Code: Select all

----------begin_max5_patcher----------
1417.3oc6Z0tahiCE82vSg2zJQREjM14CftaWsR6avt+rspxPbKYVvAkX5vp
Qy69bscBDJApgFXpVApMo4l60Get96S4asaYMJcIK2BcK5dTqVeqcqVJSRCs
Jdtk0L5xwSo4J2r3rulN5KVc0uRvVJTlEnQk13KlktPLkITAfKrpMI9u4LMZ
Vin7WrPOV754Tw3II7WdJiMVn8.i8b85hvQQxaDR40UwjDqfFpN8v3JnmvWA
tz12a2VdoqgDbdFKmIpmLA6hLkAgrR3paaZXezbfuhk39padJNG3UOMGTOKK
KbElOESEzxVzUbTGyHVVk..aq8cX2hLourRKaWYwIJBTvi6kWn4PIHqlPSA7
q0i.0zkkNAWOdjyLd90fmrHL.vWz.R7.28CkWwt3PiQN3nY57BlB+z+.xrGO
fSz.Z8WgEI3MfT+WG3PmcL2vH53ItPmy4LdLhsbNEt8mvPnulQmivG3zFFLV
x2KTMVZn+9lxXXsikHMNsUSHTGE8dWdLPMmPDduy74s24DxouxheBbDJ6mnB
QVxnEB8L9U5RY8JKKOIkuti0.OrmJWnSFMTJICnOCodr1TBYms5cMpkmDEHu
ENbuYLRi0xudr0aH58H43YDVNXF83AtXRkkQLk2djJKUF3uCh6aspfxnyXBV
1SLNczTV0tie3EP22vA1qzomfA7AJdG4sUy93zooYZW8bCBCF5gGF40ePfON
nKXJZPDoePn2vAd9CIDooAD+Pxv.XA4nf9d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