kristopolous / TickTick

JSON in your Bash scripts

Home Page:http://9ol.es/TheEmperorsNewClothes.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[feature] Included functions unable to use TickTick

donaldej opened this issue · comments

How can I get included functions into the same scope as TickTick? It seems they cant actually interact with it.

can you show me a snippet of code that you are trying?

It literally is just;

main.sh
#!/usr/bin/env bash
. ticktick.sh
. includes.sh

``
  people = {
    "HR" : [
      "Alice",
      "BoB",
      "Carol"
    ]
  }
``

firstPerson

echo "Second Person"
echo `` people.HR[1] ``

exit
includes.sh
#!/usr/bin/env bash

firstPerson() {
    echo "First Person"
    echo `` people.HR[0] ``
}
Output
First Person
people.HR[0]
Second Person
BoB

oh i see ... yes, this certainly wouldn't work.

There's unfortunately no way I can think of doing this without adding a feature.

description of feature

  1. parser needs to look for
    . (file)
  2. parser needs to run engine over (file) emitting its contents in place of dot notation
commented

+1 for this. I made the incorrect assumption it would work and now have to refactor my code. :-(

I'll write a test

tacked the tests in ... now just to make them work

been looking into this today ... trying to figure out a hack to do it. If it's not a hack, it's not ticktick. I'm certainly not going to be doing a huge honking tokenizer and parser for "source" and ".". Ok ok it may be unavoidable ... but I'm going to try

I will take a stab at it this weekend. I am curious as well :D

hah I got it!

#!/bin/bash
enable -n .
.() {
  echo "I should read $1"
}
. n.sh

lol, what a fucked up language this is. awesome.

haha Bash hell, man. Bash hell

ok so I have it loading and interpreting. I can get function scope but not variable ... anyway gotta go off to this punk concert. I'll work on it more later. Should be cake from here out.

so I can do this with temp files. no-temp-files is one of my commitments because of the side-effects being non-zero (even though they are really small). I'll do the temp-file solution for now and then open up a separate ticket to figure out how to hack a non-temp file version.

Note that simply 'evaling' as I do in one other place in the code will not work because, if you look at the source for bash, it simply treats newlines like any other whitespace ... which means that

fun() {
   echo 'hi'
}

becomes

fun() { echo 'hi' }

Which looks fine until you think like a parser... this will expand to:

fun() {
echo 'hi' '}'

two arguments for echo, followed by no closing brace. That means that you'd need a semicolon for this to work ... which puts a new restriction on code.

But wait, there's more! If you call now you'll get a commenting bug for the same reason absolutely free!

# This was written by the intern. He's a mathematician so it works but we don't know how
n_equals_np_proof() {

Becomes:

# This was written by the intern. He's a mathematician so it works but we don't know how n_equals_np_proof() { ...

Ala, one gigantic one-line comment. Splendid. So that, unfortunately will not work.

Other methods lead to subshells so that's no good. The temp file solution is there, the fruit hangs low, I might as well pick it.

How has bash survived this long XD

Thanks,
Donnie Jones

Date: Sat, 25 Jun 2016 16:51:35 -0700
From: notifications@github.com
To: TickTick@noreply.github.com
CC: donaldej@outlook.com; author@noreply.github.com
Subject: Re: [kristopolous/TickTick] [feature] Included functions unable to use TickTick (#37)

so I can do this with temp files. no-temp-files is one of my commitments because of the side-effects being non-zero (even though they are really small). I'll do the temp-file solution for now and then open up a separate ticket to figure out how to hack a non-temp file version.

Note that simply 'evaling' as I do in one other place in the code will not work because, if you look at the source for bash, it simply treats newlines like any other whitespace ... which means that

fun() {
echo 'hi'
}

becomes

fun() { echo 'hi' }

Which looks fine until you think like a parser... this will expand to:

fun() {
echo 'hi' '}'

two arguments for echo, followed by no closing brace. That means that you'd need a semicolon for this to work ... which puts a new restriction on code.

But wait, there's more! If you call now you'll get a commenting bug for the same reason absolutely free!

This was written by the intern. He's a mathematician so it works but we don't know how

n_equals_np_proof() {

Becomes:

This was written by the intern. He's a mathematician so it works but we don't know how n_equals_np_proof() { ...

Ala, one gigantic one-line comment. Splendid. So that, unfortunately will not work.

Other methods lead to subshells so that's no good. The temp file solution is there, the fruit hangs low, I might as well pick it.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

Apparently the functionality of builtin and enable doesn't match the documentation - although it looks like I can do some dance that will make it work and match the documentation for when this inconsistency is resolved. (let's not use the 'b' word here)