View Issue Details

IDProjectCategoryView StatusLast Update
0000490tcshGeneralpublic2024-06-03 14:49
ReporterMProG10 Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Summary0000490: Introduce 'function' built-in.
DescriptionThis is a wrapper around goto and source. The script recurses and searches for a goto label. It's an error for labels not contain an exit to their end. Function calls outside labels are, by default, labeled main. The use is exclusive for scripts.
Additional Informationhttps://github.com/tcsh-org/tcsh/pull/77
TagsNo tags attached.

Activities

MProG10

2023-12-02 00:49

reporter   ~0003981

sh.func.c.diff (1,931 bytes)   
sh.decls.h.diff (772 bytes)   
sh.c.diff (3,194 bytes)   
sh.err.c.diff (929 bytes)   
sh.h.diff (486 bytes)   

MProG10

2023-12-02 03:03

reporter   ~0003982

tcsh.man.in.diff (1,096 bytes)   
commands.at.diff (1,110 bytes)   
sh.init.c.diff (325 bytes)   

MProG10

2023-12-03 19:44

reporter   ~0003985

Prefer srcfile() over dosource()
sh.c-2.diff (3,818 bytes)   
sh.h-2.diff (516 bytes)   
sh.func.c-2.diff (1,765 bytes)   

MProG10

2024-02-14 14:57

reporter   ~0004011

Functions should work for sourced scripts.

Next, make a table of functions so they can be called globally. Currently, it isn't possible to call functions from sourced files other than the current.
sh.h-3.diff (720 bytes)   
sh.c-3.diff (5,424 bytes)   
sh.func.c-3.diff (2,081 bytes)   

MProG10

2024-06-03 14:34

reporter   ~0004052

I think functions based on pipes makes a simpler feature, as well as allows for use in interactive sessions, resembling Bourne-compatible Shells better. Unlike the goto-based version, functions may only be called if they were previously declared (i.e: no forward jumps), making a similar behavior to Bourne-compatible Shells.

This new version relies on a tree derived from variables and aliases. Unlike to aliases and variables, the tree is restrictive. Once a function is declared, may not be redeclared or undeclared.

I was afraid this wouldn't work out for some operations, such as loops and gotos, because pipes cannot rewind. Fortunately, I was wrong, and the fact these operations are possible from interactive sessions, from a terminal, makes the assumption just as wrong, though I'm clueless as to how the Shell handles rewinding on unsupported sources.
sh.h-4.diff (1,500 bytes)   
sh.init.c-2.diff (599 bytes)   
sh.lex.c.diff (353 bytes)   
tcsh.man.in-2.diff (1,354 bytes)   
sh.c-4.diff (1,636 bytes)   
sh.decls.h-2.diff (1,243 bytes)   
sh.err.c-2.diff (1,054 bytes)   
sh.func.c-4.diff (3,563 bytes)   

MProG10

2024-06-03 14:49

reporter   ~0004053

Recursion/nest.

Issue History

Date Modified Username Field Change
2023-12-01 21:41 MProG10 New Issue
2023-12-02 00:49 MProG10 Note Added: 0003981
2023-12-02 00:49 MProG10 File Added: sh.decls.h.diff
2023-12-02 00:49 MProG10 File Added: sh.c.diff
2023-12-02 00:49 MProG10 File Added: sh.err.c.diff
2023-12-02 00:49 MProG10 File Added: sh.func.c.diff
2023-12-02 00:49 MProG10 File Added: sh.h.diff
2023-12-02 03:03 MProG10 Note Added: 0003982
2023-12-02 03:03 MProG10 File Added: sh.init.c.diff
2023-12-02 03:03 MProG10 File Added: tcsh.man.in.diff
2023-12-02 03:03 MProG10 File Added: commands.at.diff
2023-12-03 19:44 MProG10 Note Added: 0003985
2023-12-03 19:44 MProG10 File Added: sh.h-2.diff
2023-12-03 19:44 MProG10 File Added: sh.func.c-2.diff
2023-12-03 19:44 MProG10 File Added: sh.c-2.diff
2024-02-14 14:57 MProG10 Note Added: 0004011
2024-02-14 14:57 MProG10 File Added: sh.c-3.diff
2024-02-14 14:57 MProG10 File Added: sh.h-3.diff
2024-02-14 14:57 MProG10 File Added: sh.func.c-3.diff
2024-06-03 14:34 MProG10 Note Added: 0004052
2024-06-03 14:34 MProG10 File Added: sh.init.c-2.diff
2024-06-03 14:34 MProG10 File Added: sh.lex.c.diff
2024-06-03 14:34 MProG10 File Added: tcsh.man.in-2.diff
2024-06-03 14:34 MProG10 File Added: sh.c-4.diff
2024-06-03 14:34 MProG10 File Added: sh.decls.h-2.diff
2024-06-03 14:34 MProG10 File Added: sh.err.c-2.diff
2024-06-03 14:34 MProG10 File Added: sh.func.c-4.diff
2024-06-03 14:34 MProG10 File Added: sh.h-4.diff
2024-06-03 14:49 MProG10 Note Added: 0004053