From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Functions in SBE blocks Date: Sat, 07 Jul 2012 16:02:49 -0400 Message-ID: <1372.1341691369@alphaville> References: <20120707185831.GA25982@client195-161.wlan.hu-berlin.de> Reply-To: nicholas.dokos@hp.com Return-path: Received: from eggs.gnu.org ([208.118.235.92]:49646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnbE3-0003iK-IM for emacs-orgmode@gnu.org; Sat, 07 Jul 2012 16:03:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SnbE1-0005jI-Qq for emacs-orgmode@gnu.org; Sat, 07 Jul 2012 16:03:31 -0400 Received: from vms173011pub.verizon.net ([206.46.173.11]:39151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SnbE1-0005fl-M6 for emacs-orgmode@gnu.org; Sat, 07 Jul 2012 16:03:29 -0400 Received: from alphaville.dokosmarshall.org ([unknown] [98.110.161.175]) by vms173011.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0M6T00CE23OPBLHD@vms173011.mailsrvcs.net> for emacs-orgmode@gnu.org; Sat, 07 Jul 2012 15:02:55 -0500 (CDT) Received: from alphaville (localhost [127.0.0.1]) by alphaville.dokosmarshall.org (Postfix) with ESMTP id E397A40E7D for ; Sat, 07 Jul 2012 16:02:49 -0400 (EDT) In-reply-to: Message from Viktor Rosenfeld of "Sat, 07 Jul 2012 20:58:31 +0200." <20120707185831.GA25982@client195-161.wlan.hu-berlin.de> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Viktor Rosenfeld wrote: > Hi, > > I can't get SBE blocks called from a table to work, if they use > functions like org-parse-time-string. > > Suppose I have the following table: > > | Start | Ende | | > |------------------+------------------+-| > | [2011-06-29 Wed] | [2012-02-29 Wed] | | > #+TBLFM: $3='(sbe "billable-month" (start $1) (end $2)) > > and the following source block: > > #+NAME: billable-month(start="[2011-06-29 Wed]", end="[2012-02-29 Wed]") > #+BEGIN_SRC emacs-lisp > (let* ((start-date start)) > (message "%s" start-date)) > #+END_SRC > > If I evaluate the table, the start date is put into the last column. > However, if I change the code to the following: > > #+NAME: billable-month(start="[2011-06-29 Wed]", end="[2012-02-29 Wed]") > #+BEGIN_SRC emacs-lisp > (let* ((start-date (org-parse-time-string start))) > (message "%s" (nth 4 start-date))) > #+END_SRC > > then the string #ERROR is inserted into the table. Evaluating the source > block directly yields the correct result. > > What's going on here? > Finicky type matching: if you evaluate the second code block in the buffer with ESC ESC : (sbe "billable-month" (start "[2011-06-29 Wed]") (end "[2012-02-29 Wed]")) RET you get a backtrace similar to this: ,---- | Debugger entered--Lisp error: (wrong-type-argument stringp [2011-06-29 Wed]) | string-match("\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)\\( +[^]+0-9> \n -]+\\)?\\( +\\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)" [2011-06-29 Wed]) | (if (string-match org-ts-regexp0 s) (list 0 (if (or (match-beginning 8) (not nodefault)) (string-to-number (or (match-string 8 s) "0"))) (if (or (match-beginning 7) (not nodefault)) (string-to-number (or (match-string 7 s) "0"))) (string-to-number (match-string 4 s)) (string-to-number (match-string 3 s)) (string-to-number (match-string 2 s)) nil nil nil) (error "Not a standard Org-mode time string: %s" s)) | org-parse-time-string([2011-06-29 Wed]) | (let* ((start-date (org-parse-time-string start))) (format "%d" (nth 4 start-date))) | ... `---- Somewhere, the string becomes not a string. Try modifying the block to this: #+BEGIN_SRC emacs-lisp (let* ((start-date (org-parse-time-string (format "%s" start)))) (message "%s" (nth 4 start-date))) #+END_SRC Nick