mirror of
https://github.com/not-kennethreitz/convore.json.git
synced 2026-06-17 13:41:01 +00:00
1 line
4.3 KiB
JSON
1 line
4.3 KiB
JSON
[{"user_id": 32737, "stars": [], "topic_id": 36221, "date_created": 1305985184.5112741, "message": "And here's some comparisons:", "group_id": 9739, "id": 1133919}, {"user_id": 32737, "stars": [], "topic_id": 36221, "date_created": 1305985137.8370571, "message": "A very lengthy function title, but an awesome one. Why is it so awesome, you ask? Because it lets you easily and seamlessly create a new parameter that \"inherits\" from an existing one, but changing stuff. Racket apparently uses this to throw errors, so that for instance, current-directory only allows strings or paths.\n\nBut I'm using it for something different. As mentioned earlier, I implemented an implicit curdir variable, that lets you get/set the current directory, and also has a w/curdir macro that lets you temporarily shadow it. This is an incredibly nice and convenient way to deal with directories.\n\nProblem is, curdir is implemented in terms of racket-current-directory, which returns a path object, not a string. So, with aw's cwd library (https://github.com/awwx/lib/blob/master/cwd0.arc), he hacks around this, but it feels kludgy to me. Especially since I ended up using the same technique with scripts-args...\n\nWhat we really want is a way to create a new parameter that is juuuust like an existing one, but that lets us filter it, so it returns something a little different, or maybe does some pre-processing on assignment. racket-make-derived-parameter does precisely that.\n\nSo now, the implementation of curdir and script-args is a lot cleaner, I think. It's not even that they're shorter, per se, just... cleaner. It also fixes a bug with script-args!\n\nI also changed curdir so \"~/foo\" is expanded into whatever the user's HOME directory is. So now you can do stuff like (w/curdir \"~/foo/bar\" ...) and it'll Just Work(tm).", "group_id": 9739, "id": 1133915}, {"user_id": 32737, "stars": [], "topic_id": 36221, "date_created": 1305985288.3076611, "message": "Now I'm using this:\n\n (make-implicit curdir\n (racket-make-derived-parameter racket-current-directory\n (fn (v) (racket-expand-user-path v))\n (fn (v) (racket-path->string v))))\n\n\nRather than this:\n\n (= (dynamic-parameter* 'curdir) racket-current-directory)\n (defvar curdir\n (fn () (racket-path->string (racket-current-directory)))\n (fn (v) (racket-current-directory (racket-expand-user-path v))))\n (make-w/ curdir)", "group_id": 9739, "id": 1133925}, {"user_id": 32737, "stars": [], "topic_id": 36221, "date_created": 1305985317.5045509, "message": "Now I'm using this:\n\n (make-implicit script-args\n (racket-make-derived-parameter racket-current-command-line-arguments\n (fn (v) (racket-mlist->vector v))\n (fn (v) (racket-vector->mlist v))))\n\n\nRather than this:\n\n (let cli racket-current-command-line-arguments\n (= (dynamic-parameter* 'script-args) cli)\n\n (defvar script-args\n (fn () (racket-vector->mlist (cli)))\n (fn (v) (cli (racket-mlist->vector v))))\n\n (make-w/ script-args))", "group_id": 9739, "id": 1133927}, {"user_id": 32737, "stars": [], "topic_id": 36221, "date_created": 1305985446.0531631, "message": "As for the bug with script-args, doing (= script-args '(\"foo\" \"bar\" \"qux\")) didn't work, because it wasn't doing the list->vector conversion, but now that I'm using racket-make-derived-parameter, it works just fine.", "group_id": 9739, "id": 1133931}, {"user_id": 32737, "stars": [], "topic_id": 36221, "date_created": 1305985552.213798, "message": "And here's the documentation for it: http://docs.racket-lang.org/reference/parameters.html?q=environment#%28def._%28%28quote._~23~25kernel%29._make-derived-parameter%29%29\n\n(God, Racket docs have such atrocious URLs)", "group_id": 9739, "id": 1133933}, {"user_id": 32737, "stars": [], "topic_id": 36221, "date_created": 1305985774.4625981, "message": "Er, I wasn't very clear earlier. \"~\" is expanded into the HOME directory, so \"~/foo\" would be the subdirectory \"foo\" of the HOME directory. I made it sound like \"~/foo\" was the HOME directory, but no, it's \"~\", like you would expect.", "group_id": 9739, "id": 1133953}, {"user_id": 32737, "stars": [], "topic_id": 36221, "date_created": 1305989738.814008, "message": "(Incidentally, this means that `load` now understands \"~\" in filepaths, but only because it uses w/curdir, and curdir now understands \"~\")", "group_id": 9739, "id": 1134375}] |