Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Language idea] print formatting - add to highest level #3522

Open
LeslieMurphy opened this issue Oct 28, 2022 · 0 comments
Open

[Language idea] print formatting - add to highest level #3522

LeslieMurphy opened this issue Oct 28, 2022 · 0 comments
Labels

Comments

@LeslieMurphy
Copy link

Language idea incl level
My goal was to write a multiplication table!

To make it appear nice we need to pad the shorter numbers so everything aligns.

I got it to work, but the code is a bit convoluted!

Need some sort of language function like this - which I know is way too complex for children, but maybe we can come up with a syntax?
Another concept that could help would be a print without a newline.

Ideas for hedy (I am a very poor language designer!)

print myvalue with 4 positions align left # adds crazy verbose syntax to the language :-(
print xxxx without newline # more verbose ugly syntax 
print myvalue picture "ZZZ9" # this is supported by COBOL !!!!  Zero suppression
print format(myvalue, "{:4d}") # allow any Python format to be used
or support tab stops and automatically right justify the columns) # need a directive in the language to declare the tab width(s)
set tabwidths = {5,10,10,10,10} # introduces a special variable in hedy and support for escaped \t

Example in Python

print("{:4d}".format(val) , end =" ")

Additional context

print '    1   2   3   4   5   6   7   8   9'
print '_____________________________________'
for counter in range 1 to 9
    padding0  = '   '
    padding1 =  '   '
    padding2 =  '   '
    padding3 =  '   '
    if counter >= 2
        padding3 = '  '
    if counter >= 3
        padding2 = '  '
    if counter >= 4
        padding1 = '  '
    if counter >= 5
        padding0 = '  '
    print counter " | "  counter padding0 counter*2 padding1 counter*3 padding2 counter*4 padding3 counter*5 padding3 counter*6 padding3 counter*7 padding3 counter*8 padding3 counter*9

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants