Giter VIP home page Giter VIP logo

Comments (6)

matryer avatar matryer commented on July 20, 2024

What about having T as int and use []T in your code when you need slices?

Sent from my iPhone

On 18 Sep 2015, at 16:07, falafflepotatoe [email protected] wrote:

Hey. I'm having good success with genny but now I have a spazzy-issues.

Code:

func pop(arr _T) BASETYPE { l := len(_arr)-1; val := (_arr)[l]; *arr = (_arr)[:l]; return val }
Question

How can I set basetype to "int" when T is []int? so the return type is the base type... ex: return "int" when my code generates []int., float when T is []float etc
I tried:
func pop(arr TSlice) T { l := len(arr)-1; val := (arr)[l]; *arr = (arr)[:l]; return val }

but after running go generate Tslice is named "intSlice" so I cannot export it, which is my next question:

I'm exporting my package so custom types have to be Uppercased, so the way I was building slices is no longer work

Reply to this email directly or view it on GitHub.

from genny.

falafflepotatoe avatar falafflepotatoe commented on July 20, 2024

@matryer thats what I was doing initially, however for builtins... go does not allow you to use them as receivers in functions

ex: func (arr []int) pop () {...} is invalid, so I have to use a custom type IntSlice.

from genny.

falafflepotatoe avatar falafflepotatoe commented on July 20, 2024

Question for you guys!
I want to release my generated .go file as a package
but I want to include the src/template so they can add types and regenerate it.
But the template should not be in the pkg (the code/varnames conflict as the T variables are not defined)

I guess you cannot change the extension of a file before using go generate. Any idea how to do this?

from genny.

matryer avatar matryer commented on July 20, 2024

You can use build tags to prevent template files from being build as part of the package?

// +build ignore

On 9 Oct 2015, at 10:54, falafflepotatoe [email protected] wrote:

Question for you guys!
I want to release my generated .go file as a package
but I want to include the src/template so they can add types and regenerate it.
But the template should not be in the pkg (the code/varnames conflict as the T variables are not defined)

Any idea how to do this?


Reply to this email directly or view it on GitHub #13 (comment).

from genny.

falafflepotatoe avatar falafflepotatoe commented on July 20, 2024

yea! thanks a lot sir.

from genny.

falafflepotatoe avatar falafflepotatoe commented on July 20, 2024

One last question: Im using two vars and getting 2x2x2x2 results instead of 2x2 (4) generated functions
the vars are BASE_TYPE (=int,float) and SLICE (=IntSlice,FloatSlice)
I dont need a type IntSlice []float, and a Floatslice []int

anyway to not get double the results?

from genny.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.