Home Map Index Search News Archives Links About LF
[Top bar]
[Bottom bar]
[Photo of the Author]
by Brent B. Welch

About the author:
Brent Welch �ثe���������إߤ@�� www.scriptics.com ����, �]�A�@�Ӧ���Tcl���� �� URLs ( Tcl�귽����) �å[�W���Ѫ���Ʈw�M�@��TclPro Product���q�l�Ӱȫس] (ecommerce infrastructure) �C�L�]�b�}�o�X�Ӥj���� Tcl/Tk���ε{��,�]�A���b www.scriptics.com �����W���檺Tcl Httpd web ���A���BExmh �l��ϥΪ̤����M webtk HTML �s�边�C�L�O " Tcl �M Tk �{���]�p��� (Practical Programming in Tcl and Tk)" �@�Ѫ��@�̡CWelch ��1982�~�b��ù�Ԧh�{Boulder�j�ǯ�Ťu�{�t��o �Ǥh�Ǧ�, 1986�~�b�[�{Berkeley�j�Ǩ��o��T�u�{�Ӥh�Ǧ�, 1990�~�b�[�{Berkeley �j�Ǩ��o��T�u�{�դh�Ǧ�CWelch���e�O Xerox���q PARC��s���߬�s�����@����, ��s�������t�� (distributed systems)�C�M��L�[�J Sun Microsystems ����Ǥ� Tcl/Tk�p�զ����C�L�]�O����q����|(ACM)�M��ڹq�l�u�{�v��| (IEEE) ���|���C ������}�Ghttp://www.beedub.com/

Content:

Tcl �y�k

[Ilustration]

Abstract:

�o�g�峹���ФFTcl�y�������[���M�y�k�C



 

Tcl�y�k²��

�H�@�ظ}���y���ӻ�, Tcl�㦳²�檺�y�k�C

cmd arg arg arg
�@��Tcl�R�O�O�Ѫťդ��j������r�Ҳզ��C�䤤, �Ĥ@�Ӧr�O�R�O�W��, ��l���O�R �O�Ѽ� .
$foo
���Ÿ� ($) ���N�F�ܼƪ��ȡC�b���Ҥ�, �ܼƦW�٬O foo.
[clock seconds]
��A������F�@�ӱ_���R�O (nested command)�C�Ҧp, �p�G�A�Q�ǻ��@�өR�O�����G�@?�t�~�@�өR�O���Ѽ�, ����A�����ϥγo�ػy�k�C�b�o�ӨҤl��, �_���R�O�O clock seconds, �����ѥثe�ɶ������ơC
"some stuff"
���޸��N�h�Ӧr�аO��?�R�O���@�ӳ�W�ѼơC���Ÿ� $ �M��A���b���޸����|�Q��Ķ�C
{some stuff}
�j�A���]�|��h�Ӧr�аO?�R�O���@�ӳ�W�ѼơC���L�b�o�ӨҤl����L�Ÿ��b�j�A�������Q��Ķ�C
\
�ϱ׽u�Ÿ�(\) �O�ΨӤޥίS���Ÿ��C�Ҧp�G\n �|���ʹ���C�ϱ׽u�Ÿ��]�Q�Ψ� "����" ���Ÿ� $�B�޸��B��A���M�j�A�����S���N�q�C
 

�@�Ӥp�Ҥl

�U���O�@��Tcl �R�O�ΨӦC�X�ثe�ɶ��C���ϥΤF�T��Tcl�R�O : set, clock,�M puts. set �R�O�N�ȳ]�w���ܼơCclock �R�O�B�z�ɶ��ܼơC puts �R�O�C�X���G�C

set seconds [clock seconds] puts "The time is [clock format $seconds]"

�`�N�@�U�b�]�w�ȵ��ܼƮɨå��ϥ� $ �Ÿ��C�u���b�ϥ��ܼƮɤ~�ϥ� $ �Ÿ��C�b�W�ӨҤl�� seconds �ܼƨä��O�������C�A�i�ϥΤ@�өR�O�ӦC�L�X�ثe���ɶ�:

puts "The time is [clock format [clock seconds]]"

 

�s�թM���N

�Q��Tcl parser ��RTcl�y�k�����ϥΥH�U�T�ӨB�J: �N�ѼƤ����s��, ���G���N�M�R�O����

  1. �N�ѼƤ����s��. Tcl�ݭn�M�w�p���´�R�O���ѼơC�b��²�檺���p��, �����Q�Ϊťդ��j�ѼơC���e����L, �޸��M�A���y�k�i���h������r�զ��@�ӰѼơC�b�e�ӨҤl��, ���޸��ΨӲզ� puts�R�O���@�ӰѼơC

  2. ���G���N. �b�ѼƤ����s�ի�, Tcl����r����N�CPut�R�O��, �u�O²����ܼ� $foo���ȴ��N�F foo, �ε��G���N�F�A���R�O�C���N�O�b���դ���i�檺�C�o�ئ��ǨϯS�O���Ȩå��ϩR�O���c�ܽ���.

  3. �R�O����. �b���G���N��, Tcl �ϥΩR�O�W�ٷ�����Ȩӷj�M������ (Dispatch Table) , ���I�s�����۹����� C �{��, �M�ᦹ C �{�ǬO�ΨӰ���R�O���C�A�]�i�ϥ� Tcl �Ӽ��g�R�O�{�ǡC�Ӧ��ص{�Ǧb�Ѽƶǻ��P���~�B�z�����@��²�檺�W�w�C
 

�t�@�ӨҤl

�U���O�t�@�ӨҤl:

set i 0 while {$i < 10} { puts "$i squared = [expr $i*$i]" incr i }

�b���B, �j�A���ΨӱN�ѼƤ���, �B�èS����������N�C Tcl parser �F�� while�R�O�èS���S�O���a��, �N����ݨ䥦���@��R�O�@�ˡC while �R�O�Q�� Tcl Parser ����, �i���D�Ĥ@�ӰѼƬO�B�⦡, �ӲĤG�ӰѼƫh�O�h�� Tcl �R�O�C �j�A���N��������ӰѼ�:�޿�B�⦡�P����j��, Tcl �R�O�b�j�鳡���C

�ڭ̬ݨ�F��ӼƾǹB�⦡: ���L�N�Ƥ���M���k�B��Cwhile �R�O�۰ʱN�@�ӰѼƭȷ��@�B�⦡�ӭp��C�b��L�����p�U, �z�n���T�ϥ� expr �R�O�Ӱ���ƾǹB��  

�R�O����

�̫�, Tcl �I�s�䥦�{�ǨӳB�z�x�����u�@�C�ڭ̤w�g�i�ݨ� Tcl �ϥ� expr�R�O�Ӱ���ƾǨ��, puts �R�O�ӳB�z��X�\��, set �R�O�ӳ]�w�ȵ��ܼơC�o�� Tcl �R�O�O�z�L�����w�b Tcl ���n���L (Registered) �� C �y���{�ǨӰ��檺�CC �y�����R�O�{�ǥ� Tcl �R�O���o�r��Ѽ�, �M��Ǧ^�@�ӵ��G���@�ӷs���r��C�Q�n���g C �y���R�O�{�ǫ�²��C���i�H������Ʊ�, �]�A�s����Ʈw�M�إ߹ϧΨϥΪ̤����CTcl�y��, �ä����D�R�O�|������˪��\�� , ���u�O�Q�ΰѼƤ��s��, ���G���N�M�R�O�����T�B�J�Ӱ���R�O�C  

�̫�@�ӨҤl

�o�̬O�@�Ӷ����{��:

proc fac {x} {
    if {$x < 0} {
        error "Invalid argument $x: must be a positive integer"
    } elseif {$x <= 1} {
        return 1
    } else {
        return [expr $x * [fac [expr $x-1]]]
    }
}


 

��i�@�B���\Ū

����X�B: Scriptics
����½Ķ: �}�l�W (Kevin Hsu)
Webpages maintained by the LinuxFocus Editor team
© Brent B. Welch
LinuxFocus 1999
Translation information:
en -> -- Brent B. Welch
en -> cn Kevin Hsu

1999-10-28, generated by lfparser version 0.8