From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/107779 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Hans van der Meer Newsgroups: gmane.comp.tex.context Subject: Re: Checking existence of a macro (control sequence) by Lua - problem after updating MkIV Date: Thu, 18 Jun 2020 12:21:49 +0200 Message-ID: <4A610884-7395-45B9-9D92-DF0409B440F2@ziggo.nl> References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\)) Content-Type: multipart/mixed; boundary="===============1100008963196869669==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="47149"; mail-complaints-to="usenet@ciao.gmane.io" To: NTG ConTeXt Original-X-From: ntg-context-bounces@ntg.nl Thu Jun 18 12:22:16 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jlrgV-000C8l-Cq for gctc-ntg-context-518@m.gmane-mx.org; Thu, 18 Jun 2020 12:22:15 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 444A8163A66; Thu, 18 Jun 2020 12:21:55 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IqCSHTA1663v; Thu, 18 Jun 2020 12:21:52 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 832DD16362F; Thu, 18 Jun 2020 12:21:52 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id D3CFC16362F for ; Thu, 18 Jun 2020 12:21:51 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xXeKumWVWAfB for ; Thu, 18 Jun 2020 12:21:50 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=212.54.42.166; helo=smtpq3.tb.mail.iss.as9143.net; envelope-from=havdmeer@ziggo.nl; receiver= Original-Received: from smtpq3.tb.mail.iss.as9143.net (smtpq3.tb.mail.iss.as9143.net [212.54.42.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id DDBA0162F45 for ; Thu, 18 Jun 2020 12:21:50 +0200 (CEST) Original-Received: from [212.54.42.137] (helo=smtp6.tb.mail.iss.as9143.net) by smtpq3.tb.mail.iss.as9143.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jlrg6-0004Pw-IE for ntg-context@ntg.nl; Thu, 18 Jun 2020 12:21:50 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ziggo.nl; s=202002corplgsmtpnl; h=To:Date:Subject:From; bh=7hJIA1TyyLzfLibywolPqfPG8mdfHZMQw6Qhf/6pDRE=; b=cZiVdssvJPNHNrh0Rp5cUoJH8G VeDSUWPbwBaNhOhPq5wkmKElPybBixYJpQnXFE1y0MJ9Uqjheo54MfasH9WDdT/9hhe2xBGrsu3WH aoySj4x8pps5RePR22DCWpujZzSa1QJkaQigvsA4rDqxAW0aFqt55xoP74Pl7DGXcHcGnqhRDxegM d8WTuvhTGWvO56vve2kA6DHinGRAycI4fAqsmOTY/NFfxEP2drrShYJASeJCu9VjCdlVYUzHrPYnZ 115sObNxQJRWMcg5QWQBhIi2vfjG+YZo438MzdYBAp8Ai3qFuGMMS7J/2UvGnGFZFEDbnpEgsH0v9 v93yby/g==; Original-Received: from 84-106-134-200.cable.dynamic.v4.ziggo.nl ([84.106.134.200] helo=[192.168.178.15]) by smtp6.tb.mail.iss.as9143.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jlrg6-001cf9-7L for ntg-context@ntg.nl; Thu, 18 Jun 2020 12:21:50 +0200 In-Reply-To: X-Mailer: Apple Mail (2.3608.80.23.2.2) X-SourceIP: 84.106.134.200 X-Authenticated-Sender: havdmeer@ziggo.nl (via SMTP) X-Ziggo-spambar: / X-Ziggo-spamscore: 0.0 X-Ziggo-spamreport: CMAE Analysis: v=2.3 cv=KbhJTTQD c=1 sm=1 tr=0 a=wCstmS+ZHA3zSJXjQC+ubA==:17 a=9+rZDBEiDlHhcck0kWbJtElFXBc=:19 a=nTHF0DUjJn0A:10 a=MiNTnEJAAAAA:8 a=YEMqx4UAAAAA:8 a=ACQCx6kCAAAA:8 a=xtERp6CFAAAA:8 a=a3nu-2BBAAAA:8 a=vn2sti7V5wjfT4xYF1QA:9 a=CjuIK1q_8ugA:10 a=KUVUyp9iF3ef2q-EXQYA:9 a=n_xlARJGUR_xo0Dn:21 a=_W_S_7VecoQA:10 a=evSma_05QfcA:10 a=LmrbSfiT3hecnSZifb5M:22 a=V0662LiR8DSfwiDagK97:22 a=Sab0UneHBzlWrQDlOuxD:22 a=ekCXXmE-vB8RPiJ3MEZb:22 X-Ziggo-Spam-Status: No X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:107779 Archived-At: --===============1100008963196869669== Content-Type: multipart/alternative; boundary="Apple-Mail=_7E1F845F-9A63-456D-A99A-3F52EB04FCF7" --Apple-Mail=_7E1F845F-9A63-456D-A99A-3F52EB04FCF7 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Why can you not simply use one of the doifundefined macro's? Something = for example: \doifundefined{ExitStatus}{\gdef\ExitStatus{0}} % default to ok as in = UNIX dr. Hans van der Meer > On 18 Jun 2020, at 10:27, Lukas/ConTeXt wrote: >=20 > Hello, > I'm using Hans' macro suggested some time before. > I've just updated Ctx MkIV and my sample code: >=20 > ---- > \starttext > \def\MyMacro{Ahoj} >=20 > \def\MyMacWithPars#1#2{Something} >=20 > \def\Undefined{} > \let\Undefined\undefined >=20 > \def\DoNothing{} > \let\DoNothing\donothing >=20 > \startluacode > if CONTEXTLMTXMODE =3D=3D 0 then > local d =3D tokens.defined > local c =3D tokens.create >=20 > function tokens.defined(s,b) > if b then > return d(s) > else > return c(s).cmd_name =3D=3D "undefined_cmd" > end > end > end >=20 > -- >=20 > local defined =3D tokens.defined >=20 > for _, v in ipairs{ "MyMacro", "MyMacWithPars", "Undefined", = "DoNothing", "NonExisting" } do > print(string.format("\letterpercent-12s", v), defined(v), = defined(v, true), defined(v, false)) > end > \stopluacode >=20 > Aaa > \stoptext > ---- >=20 > gives: > " > MyMacro false false false > MyMacWithPars false false false > Undefined false false false > DoNothing false false false > NonExisting false false false > " >=20 > IOW, I'm not able to determine whether a control sequence has not been = defined (or has \undefined value) or not. >=20 > Am I doing a trivial mistake or has anything changed? >=20 > Thank you for patience... >=20 > = Lukas______________________= _____________________________________________________________ > If your question is of interest to others as well, please add an entry = to the Wiki! >=20 > maillist : ntg-context@ntg.nl / = http://www.ntg.nl/mailman/listinfo/ntg-context > webpage : http://www.pragma-ade.nl / http://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > = __________________________________________________________________________= _________ --Apple-Mail=_7E1F845F-9A63-456D-A99A-3F52EB04FCF7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Why can you not simply use one of the doifundefined = macro's? Something for example:
\doifundefined{ExitStatus}{\gdef\ExitStatus{0}} % default = to ok as in UNIX

dr. Hans van der Meer


On 18 Jun 2020, at 10:27, Lukas/ConTeXt <lpr.context@email.cz> wrote:

Hello,
I'm using Hans' macro suggested some = time before.
I've just updated Ctx MkIV and my sample = code:

----
\starttext
 \def\MyMacro{Ahoj}

=  \def\MyMacWithPars#1#2{Something}

=  \def\Undefined{}
 \let\Undefined\undefined

 \def\DoNothing{}
=  \let\DoNothing\donothing

=  \startluacode
   if CONTEXTLMTXMODE = =3D=3D 0 then
=        local d =3D tokens.defined
       local c =3D = tokens.create

=        function = tokens.defined(s,b)
=            if b = then
=             &n= bsp;  return d(s)
=            else
=             &n= bsp;  return c(s).cmd_name =3D=3D "undefined_cmd"
= =            end
       end
=    end

=    --

=    local defined =3D tokens.defined

   for _, v in ipairs{ "MyMacro", = "MyMacWithPars", "Undefined", "DoNothing", "NonExisting" } do
=      print(string.format("\letterpercent-12s", = v), defined(v), defined(v, true), defined(v, false))
=    end
 \stopluacode

 Aaa
\stoptext
----

gives:
"
MyMacro =         false   false =   false
MyMacWithPars   false =   false   false
Undefined =       false   false =   false
DoNothing =       false   false =   false
NonExisting =     false   false   false
"

IOW, I'm not able to determine = whether a control sequence has not been defined (or has \undefined = value) or not.

Am I doing a trivial mistake = or has anything changed?

Thank you for = patience...

Lukas<IsMac= Def3.log><IsMac= Def3.mkiv><IsMac= Def3.log_>______________________________________________________= _____________________________
If your question is of = interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : = https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
_______________________________________________________________= ____________________

= --Apple-Mail=_7E1F845F-9A63-456D-A99A-3F52EB04FCF7-- --===============1100008963196869669== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============1100008963196869669==--