From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21474 invoked by alias); 21 Apr 2016 04:13:19 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 21465 Received: (qmail 14305 invoked from network); 21 Apr 2016 04:13:16 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.1 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-users@zsh.org To: zsh-users@zsh.org From: Emanuel Berg Subject: Re: virtual files? Date: Thu, 21 Apr 2016 04:12:59 +0000 Message-ID: <87zisneh10.fsf@student.uu.se> References: <8760vdrt5y.fsf@student.uu.se> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: c-9ce1e655.08-680-7570702.cust.bredbandsbolaget.se Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) Cancel-Lock: sha1:P9g6+va17ab2YQxvkafnIM0rylk= "Benjamin R. Haskell" writes: > Using the `=()` substitution ZyX mentions: > > inflation () { > local usd=${1:-10} > # year > local then=${2:-1950} > local now=`date +"%Y"` > local link=" > http://data.bls.gov/cgi-bin/cpicalc.pl?cost1=$usd&year1=$then&year2=$now" > () { > local tmp=$1 > wget -q $link -O $tmp > echo -n \$ > grep \"answer\" $tmp | cut -d \$ -f 2 | cut -d \< -f 1 > } =(:) > } Great! If was something like that I had in mind. Tho the mental image was more like the Lisp syntax for doing scopes, e.g. `let' and `with-selected-frame' in: (defun new-frame-show-grep () (let ((new-frame (make-frame-command))) (setq *grep-frame* new-frame) (with-selected-frame new-frame (switch-to-buffer "*grep*") ))) Actually the zsh anonymous function syntax doesn't remind me of anything I've seen, save for perhaps some stuff in zsh itself. The parameter list and body without a name make sense, but what comes after the closing curly bracket looks like a ghost, wearing a tie... What is the colon in =(:) - an "anonymous function qualifier"? Only remark is, if you do all this trouble to get clean code, and then name the local "tmp", it is almost comical. But I get it, you did that for me (all readers), not the code per se... > Also, I prefer `curl` over `wget`, and if you're > curious, here's how I might write the entire > function: I have used them both and never reflected on which was superior, but taking a look at your code: > inflation() { > curl -s -d cost1=${1:-10} -d year1=${2:-1950} -d year2=$(date +%Y) \ > http://data.bls.gov/cgi-bin/cpicalc.pl | > awk '/"answer"/' | > tr -d -c '$0-9.,\n' > } I agree that using the --data's to set up the CGI-to-be-Perl-input arguments is less hackish than putting together the URL manually (fine, just once, but anyway is much less clear). Ironic thing is, doing it manually might actually be faster since you can then just copy-paste and modify the URL. So anyway I changed to curl, only I somewhat didn't use your compact style. awk instead of grep in this context should be strange to many who are more familiar with grep, but grep has the problem that many like to put colorization to it which can screw up parsing. If the configuration is in an environmental, I suppose not even giving the full path to the binary to bypass an alias would get them away. One can supply a specification, of course, telling grep not to use colors, but rather than doing that, I switched to awk as you suggested. I also changed the two cut:s for tr, and date +%Y from the `one` syntax form into $(another). Those I consider even more minor improvements, however they are still better so I changed them as well. If it is meaningless to do, I might as well do it! So here is the latest version: inflation () { local url=http://data.bls.gov/cgi-bin/cpicalc.pl curl -s \ -d cost1=${1:-10} \ -d year1=${2:-1950} \ -d year2=$(date +%Y) $url | awk '/"answer"/' | tr -d -c '$0-9.,\n' } One interesting thing is tho I changed three programs out of three used, I don't think this function is anything "remote" to the one I originally wrote. A small homage to the diversity of the Linux/Unix tools, I suppose. But come to think of it there are many players in the NHL that score some ~15 goals every season, but that doesn't mean they cannot also be completely different players, physical aspects as well as those of skill and style... > (Though the create-a-tempfile problem is certainly > interesting in its own right.) Yes. It cannot be like this for too many steps, is my take: a | b | ... | n But this looks like some TI-82 stuff I kid would do let f=file_path # do things to f rm $f As for now, what I'll do is to keep it short, stupid! (KISS - Thatcher quote, I think) and so be able to put together parsings, and when that doesn't work as in longer pieces of software, I'll consider getting som order by use of the anonymous software. http://user.it.uu.se/~embe8573/conf/.zsh/money -- underground experts united .... http://user.it.uu.se/~embe8573 Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic - so far: 26 Blogomatic articles -