Title: List comprehension calling randint() or a user-defined function: SyntaxError (await inside non-async IIFE) · Issue #219 · vpython/glowscript · GitHub
Open Graph Title: List comprehension calling randint() or a user-defined function: SyntaxError (await inside non-async IIFE) · Issue #219 · vpython/glowscript
X Title: List comprehension calling randint() or a user-defined function: SyntaxError (await inside non-async IIFE) · Issue #219 · vpython/glowscript
Description: Summary A list comprehension that calls random.randint(), or any function defined in the program, fails to run. It fails in Web VPython 3.2 on glowscript.org, both before and after #215. Here is the error in Chrome: SyntaxError: Unexpect...
Open Graph Description: Summary A list comprehension that calls random.randint(), or any function defined in the program, fails to run. It fails in Web VPython 3.2 on glowscript.org, both before and after #215. Here is th...
X Description: Summary A list comprehension that calls random.randint(), or any function defined in the program, fails to run. It fails in Web VPython 3.2 on glowscript.org, both before and after #215. Here is th...
Opengraph URL: https://github.com/vpython/glowscript/issues/219
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"List comprehension calling randint() or a user-defined function: SyntaxError (await inside non-async IIFE)","articleBody":"## Summary\n\nA list comprehension that calls `random.randint()`, or any function defined in the program, fails to run. It fails in Web VPython 3.2 on glowscript.org, both before and after #215. Here is the error in Chrome:\n\n```\nSyntaxError: Unexpected identifier 'randint'\n```\n\nSafari says `Unexpected identifier 'randint'. Expected ')' to end a compound expression.`\n\n## Reproduce\n\n```python\nWeb VPython 3.2\nfrom random import randint\nprint([randint(-2, 2) for i in range(20)])\n```\n\nA function you define yourself fails the same way:\n\n```python\nWeb VPython 3.2\ndef f(a):\n return a\nprint([f(i) for i in range(3)])\n```\n\nThese work:\n\n- `[random() for i in range(3)]` and `[abs(-i) for i in range(3)]`, which call built-ins\n- the same `randint` calls in an ordinary `for` loop with `L.append(...)`\n\n## Cause\n\nThe GlowScript compiler puts `await` in front of calls to functions defined in the program. That's why `randint` counts: it's defined in Python in the random stub that `GScompiler.js` injects. RapydScript compiles a comprehension into a plain, non-async IIFE, so the `await` lands where JavaScript doesn't allow it:\n\n```js\nprint((function() {\n var ρσ_Iter = range(3), ρσ_Result = [], i;\n ...\n for (var ρσ_Index of ρσ_Iter) {\n i = ρσ_Index;\n ρσ_Result.push((await f(i))); // await inside a non-async function\n }\n ...\n})());\n```\n\nHere `f` isn't even async (`function f(a) { return a; }`), so the `await` isn't needed in the first place.\n\n## Possible fixes\n\n1. Skip inserting `await` inside comprehension bodies, unless the called function is actually async (for example, it calls `rate()` or `sleep()`).\n2. Or emit the comprehension IIFE as `(async function(){...})()` and `await` it. That also needs `await` at the call site, which brings back the same problem when nested.\n\nOption 1 is probably simpler. There's a related known gap in the async transform: `_async_transform` misses namespaced calls such as `vp.rate()`.\n\nFound while validating #215. Tested with GlowScriptOffline built from master (b8a6fa1) and from the #215 merge, driven by Playwright, in both Chromium and WebKit.\n\n🤖 Generated with [Claude Code](https://claude.com/claude-code)\n","author":{"url":"https://github.com/sspickle","@type":"Person","name":"sspickle"},"datePublished":"2026-11-01T09:21:29Z","url":"https://github.com/vpython/glowscript/issues/219"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:047d841d-6134-3bc8-1678-6a0b923aff61 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9FBE:39827A:592F99:7D122C:6B0077CE |
| html-safe-nonce | 3f1b316ed6e3e21060196c1dac8b86bf82a666f577e2081e0d169e1e5decee89 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkJFOjM5ODI3QTo1OTJGOTk6N0QxMjJDOjZCMDA3N0NFIiwidmlzaXRvcl9pZCI6IjkwMjc3NDQyMjgzMDE2MzM0ODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 591cd4ba25e838195dd82fe2e3de3362cdf7811cf6345dd1343f073effd5e188 |
| hovercard-subject-tag | issue:6145314304 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/vpython/glowscript/219/issue_layout |
| twitter:image | https://opengraph.githubassets.com/810addaa5f3b2637c3bce429244104d7be9c84296a31c71ffdc5821beb6187ca/vpython/glowscript/issues/219 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/810addaa5f3b2637c3bce429244104d7be9c84296a31c71ffdc5821beb6187ca/vpython/glowscript/issues/219 |
| og:image:alt | Summary A list comprehension that calls random.randint(), or any function defined in the program, fails to run. It fails in Web VPython 3.2 on glowscript.org, both before and after #215. Here is th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sspickle |
| hostname | github.com |
| expected-hostname | github.com |
| None | 75c2b65dd205f26961d0c29afed1a8d0bb7cca9f05780571dfd1ef93eb539d16 |
| turbo-cache-control | no-preview |
| go-import | github.com/vpython/glowscript git https://github.com/vpython/glowscript.git |
| octolytics-dimension-user_id | 1280757 |
| octolytics-dimension-user_login | vpython |
| octolytics-dimension-repository_id | 187905631 |
| octolytics-dimension-repository_nwo | vpython/glowscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 187905631 |
| octolytics-dimension-repository_network_root_nwo | vpython/glowscript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 84e563eb4b55f8fa102f325f117533cee9e3df4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width