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

auto-conversion strings/list #15

Open
nylki opened this issue Jan 7, 2017 · 0 comments
Open

auto-conversion strings/list #15

nylki opened this issue Jan 7, 2017 · 0 comments

Comments

@nylki
Copy link
Owner

nylki commented Jan 7, 2017

Idea: If axiom is a string: just use string operations (because they are faster), but once a production tries to return an object, transform axiom into list of objects so it can work without errors.

Vice versa, when the axiom is a list of objects, any productions result that is only strings would be auto-transformed into list of objects.

This makes it possible to write shorter productions in productions where you eg. don't need parameters, while maintaining flexibility when you want to use a more complex (context sensitive, parametric) production.

Instead of writing

let lsystem = new LSystem({
	axiom: [{symbol: 'A'}, {symbol: 'B', myParameter: 23}, {symbol: 'C'}],
	productions: {
		'A': [{symbol: 'B'}, {symbol: 'A'}, {symbol: 'B'}, {symbol: 'A'}, {symbol: 'A'}]
		'B': ({part, myParameter}) => {return (myParameter === 23) ? {symbol: 'C'} : part},
		'C': [{symbol: 'B'}, {symbol: 'A'}]
	}
})

You could write:

let lsystem = new LSystem({
	axiom: [{symbol: 'B'}, {symbol: 'B', myParameter: 23}, {symbol: 'C'}],
	productions: {
		'A': 'BABAA'
		'B': ({part, myParameter}) => {return (myParameter === 23) ? {symbol: 'C'} : part},
		'C': 'AB'
	}
})

Should then also mixed iterables be allowed? like:

'B': ['BC', {symbol: 'B', myParameter: 23}, 'C']

Or would it create too much oerhead in general?

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

No branches or pull requests

1 participant