From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KOzlMr770V7qLwAA0tVLHw (envelope-from ) for ; Sat, 30 May 2020 06:22:54 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id FrusLr770V7xMAAAbx9fmQ (envelope-from ) for ; Sat, 30 May 2020 06:22:54 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9B62394038E for ; Sat, 30 May 2020 06:22:53 +0000 (UTC) Received: from localhost ([::1]:33936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeutQ-0000A0-Ie for larch@yhetil.org; Sat, 30 May 2020 02:22:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeusy-00009j-Ga for emacs-orgmode@gnu.org; Sat, 30 May 2020 02:22:25 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:50228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeusw-0007WS-0H for emacs-orgmode@gnu.org; Sat, 30 May 2020 02:22:23 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id DB7B955F07; Sat, 30 May 2020 02:22:18 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:in-reply-to:references:date:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=wOe8iQWymZ56 uh7t4eNQu4VERMU=; b=QoYVGaAopk2WY5fias4r5k3NbeRHftsWcW/QXwVi8I6T q4d49BqbmCg5qrX1J27CwvjZVDjYaWnIem4pQrJBCwyo2IL417OszAFJpT8CsWWd iR0JLRQhJ3GqFf0sEX3S4yta4qp1Jc9PMQSCcQRj6d5dSNQtGw2XClzvri4vLwg= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id C310D55F06; Sat, 30 May 2020 02:22:18 -0400 (EDT) (envelope-from kyle@kyleam.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=kyleam.com; h=from:to:subject:in-reply-to:references:date:message-id:mime-version:content-type:content-transfer-encoding; s=mesmtp; bh=Klfq73KNiIC/ioRQlhH7LhERW41akMwk410ekbDeNqI=; b=l7xdezW+OG8fFdsJrvZ2iM58pZhAPH1oUr6a1V4eph1PHahLvFdpXawQVNdR6fBbvOsXRdPc7q8tIfQRm4pGst8gRMCpJ0v1BOmAhwZGTvIa07fROpByImXnRY/dFnTm3ClChohExPnd/fT/cvB0QaYaWpZtNEX96NdXBc2mSSI= Received: from localhost (unknown [45.33.91.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 1A4ED55F05; Sat, 30 May 2020 02:22:18 -0400 (EDT) (envelope-from kyle@kyleam.com) From: Kyle Meyer To: Mario Frasca , emacs-orgmode@gnu.org Subject: Re: `with` as a list. In-Reply-To: <656b815f-9e38-e68c-b7a3-091f6f3d36bf@anche.no> References: <656b815f-9e38-e68c-b7a3-091f6f3d36bf@anche.no> Date: Sat, 30 May 2020 06:22:17 +0000 Message-ID: <87tuzyueli.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pobox-Relay-ID: E96DD5FC-A23D-11EA-9B3F-D1361DBA3BAF-24757444!pb-smtp2.pobox.com Received-SPF: pass client-ip=64.147.108.71; envelope-from=kyle@kyleam.com; helo=pb-smtp2.pobox.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/30 02:22:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=pobox.com header.s=sasl header.b=QoYVGaAo; dkim=pass header.d=kyleam.com header.s=mesmtp header.b=l7xdezW+; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.21 X-TUID: RifJ2y4wnFPx Mario Frasca writes: > now and then I use emacs to make graphs.=C2=A0 now recently I was plottin= g=20 > point data, and a running average "fit", so I wanted to have points, and= =20 > lines, which I know it's possible in `gnuplot` but now how do I do that=20 > from org-plot =E2=80=A6 > > I wrote a small patch for org-plot.el, I'm not a Lisp programmer so I'm=20 > sure the patch looks terrible, but it does allow me to do this: > > #+PLOT: ind:1 deps:(3 6 4 7) with:(points lines points lines) > > it's two additions: [...] Thanks for the patch and for clearly describing the motivation. I'm not an org-plot user, but the change sounds useful. (It'd be great if org-plot users could chime in.) Two meta-comments: * Please provide a patch with a commit message. See for more information. * The link above also explains the copyright assignment requirement for contributions. Please consider assigning copyright to the FSF. > diff --git a/lisp/org-plot.el b/lisp/org-plot.el > index a23195d2a..87a415137 100644 > --- a/lisp/org-plot.el > +++ b/lisp/org-plot.el > @@ -179,6 +179,28 @@ and dependent variables." > (setf back-edge "") (setf front-edge "")))) > row-vals)) >=20=20 > +(defun org-plot/zip-deps-with (num-cols ind deps with) > + "describe each column to be plotted as (col . with)" This doesn't match the convention used in this code base for docstrings. Taking a look around should give you a good sense, but (1) the first word should be capitalized, (2) sentences should end with a period, and (3) ideally all parameters should be described in the docstring. > + ;; make 'deps explicit I think this and the other comments in this function could safely be dropped. > + (unless deps > + (setf deps (let (r) > + (dotimes (i num-cols r) > + (unless (eq num-cols (+ ind i)) > + (setq r (cons (- num-cols i) r))))))) Hmm, org-plot does seem to use setf a lot (more than any other .el file in the repo), though using setq unless setf is needed would be more consistent with this code base. The code above looks fine to me. Another option would be to use number-sequence and then filter out the ind value. > + ;; make sure 'with matches 'deps > + (unless with > + (setf with "lines")) > + (unless (listp with) > + (setf with (mapcar (lambda (x) with) deps))) This is make-list in the more recent diff you sent, which I agree is better. > + ;; invoke zipping function on converted data > + (org-plot/zip deps with)) > + > +(defun org-plot/zip (xs ys) > + (unless > + (null xs) > + (cons (cons (car xs) (or (car ys) "lines")) Is the "lines" fall back ever reached? It looks like you're extending `with' above to be the same length as `deps`. > + (org-plot/zip (cdr xs) (cdr ys))))) In Elisp, it's not very common to use recursive functions (and there's no TCO). In the case of zipping two lists, I think it'd probably be easiest to just use cl-loop. And in my view having a separate function here is probably an overkill. > (defun org-plot/gnuplot-script (data-file num-cols params &optional pref= ace) > "Write a gnuplot script to DATA-FILE respecting the options set in PAR= AMS. > NUM-COLS controls the number of columns plotted in a 2-d plot. > @@ -240,22 +262,22 @@ manner suitable for prepending to a user-specified = script." > "%Y-%m-%d-%H:%M:%S") "\""))) > (unless preface > (pcase type ; plot command > - (`2d (dotimes (col num-cols) > - (unless (and (eq type '2d) > - (or (and ind (equal (1+ col) ind)) > - (and deps (not (member (1+ col) deps))))) > - (setf plot-lines > - (cons > - (format plot-str data-file > - (or (and ind (> ind 0) > - (not text-ind) > - (format "%d:" ind)) "") > - (1+ col) > - (if text-ind (format ":xticlabel(%d)" ind) "") > - with > - (or (nth col col-labels) > - (format "%d" (1+ col)))) > - plot-lines))))) > + (`2d (dolist > + (col-with > + (org-plot/zip-deps-with num-cols ind deps with)) > + (setf plot-lines > + (cons > + (format plot-str data-file > + (or (and ind (> ind 0) > + (not text-ind) > + (format "%d:" ind)) "") > + (car col-with) > + (if text-ind (format ":xticlabel(%d)" ind) "") > + (cdr col-with) > + (or (nth (1- (car col-with)) > + col-labels) > + (format "%d" (car col-with)))) > + plot-lines)))) I haven't looked at this bit too closely (and I know the handling around col-labels changed a bit in the last message you sent), but I did try out a few org-plot invocations and things seemed to work as I expected. I'll plan to take a closer when you send a reroll. > @@ -320,7 +343,7 @@ line directly before or after the table." > 0) > (plist-put params :timeind t) > ;; Check for text ind column. > - (if (or (string=3D (plist-get params :with) "hist") > + (if (or (and (stringp with) (string=3D with "hist")) Could be simplified by using `equal'. Thanks again for the patch.