[go-nuts] Re: Go eval the source

2017-07-21 Thread Nathan Kerr
A couple other options:

1. modify your code, compile, run
2. put most of your code in main.go, each specific sort method in a 
separate file (e.g., specific.go) so that go run main.go specific.go will 
use the sorting you need. See https://pocketgophers.com/10-to-instrument/ 
for an example of this setup.

On Friday, July 21, 2017 at 9:31:26 PM UTC+2, Tong Sun wrote:
>
> Hi, 
>
> I've done some searching before posting, so I know there are a few 
> packages out there that can do go eval, but am wondering which one best 
> suits the following purpose --
>
> I want to sort JSON array using Go, because each case would be different 
> for the different JSON arrays that I'm sorting, and this is only for myself 
> (to get the job done), so I want to do it as simple as possible. Thus 
> defining the sort comparing functions on the fly for the very JSON I'm 
> sorting at the moment seems to be the easiest route. 
>
> Is it so? Any better way to do it?
> Is https://github.com/sbinet/go-eval still the best package for doing go 
> eval like above?
>
> Thanks
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Going places

2017-07-21 Thread Brian Ketelsen
Congrats - that's awesome - I beat you by a few years though :)



On Friday, July 21, 2017 at 12:03:03 PM UTC-4, Michael Jones wrote:
>
> Maybe not news, and certainly not big news, but I just filed a patent that 
> uses Go source code to illustrate logical methods claimed in the invention. 
> So if it was not already the case, Go has now been used in patent filings.
>
> -- 
> Michael T. Jones
> michae...@gmail.com 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Go eval the source

2017-07-21 Thread Tong Sun
Hi, 

I've done some searching before posting, so I know there are a few packages 
out there that can do go eval, but am wondering which one best suits the 
following purpose --

I want to sort JSON array using Go, because each case would be different 
for the different JSON arrays that I'm sorting, and this is only for myself 
(to get the job done), so I want to do it as simple as possible. Thus 
defining the sort comparing functions on the fly for the very JSON I'm 
sorting at the moment seems to be the easiest route. 

Is it so? Any better way to do it?
Is https://github.com/sbinet/go-eval still the best package for doing go 
eval like above?

Thanks


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: No Allman-Style, No go!

2017-07-21 Thread ecstatic . coder
That's the problem. Indentation style should remain personal, as it's a 
matter of taste.

Every development team should have the right to freely choose which coding 
standard they will enforce.

On Friday, July 21, 2017 at 3:22:50 PM UTC+1, Hrobjartur Thorsteinsson 
wrote:
>
> Best just to call this golang style, or the wrong K style. They have 
> converted their own style into syntax.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Going places

2017-07-21 Thread Henrik Johansson
I am feeling slightly ambivalent but cool and congrats!

fre 21 juli 2017 kl 18:02 skrev Michael Jones :

> Maybe not news, and certainly not big news, but I just filed a patent that
> uses Go source code to illustrate logical methods claimed in the invention.
> So if it was not already the case, Go has now been used in patent filings.
>
> --
> Michael T. Jones
> michael.jo...@gmail.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Going places

2017-07-21 Thread Michael Jones
Maybe not news, and certainly not big news, but I just filed a patent that
uses Go source code to illustrate logical methods claimed in the invention.
So if it was not already the case, Go has now been used in patent filings.

-- 
Michael T. Jones
michael.jo...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Code Review - Applying functions on custom types

2017-07-21 Thread Sofiane Cherchalli
Hi Rog,

Please inline comments.

Thx


On Thursday, July 20, 2017 at 1:58:09 PM UTC+2, rog wrote:
>
> I'm not convinced that holding all your values in a uniform way
> is going to be that helpful for you. You might be better using reflection
> to map the columns into a struct type (there's probably a package
> out there already that can do that).
>
> However, to answer without questioning the whole premise:
>
> You can't pass a function on a specific type to the more generally
> typed func(Valuer)Valuer because the value in the column might not
> be of the specific type - what should happen if the column is a string
> and you pass func(CSVFloat)CSVFloat to Apply?
>

Couldn't do checking with for instance reflection?
 

>
> Here's your code made to work, with some arguably redundant stuff
> removed. The Transformer type seemed unnecessary, as Apply
> and RemoveColumn both work with the row in place. The Type field
> in the Column struct seemed unnecessary, as the type is implied by
> the value in the column. Also, the whole notion of Type seemed
> a bit redundant as CSV files have no notion of type, and it seems like
> you want to support custom types. The CSV prefix on the type names
> seemed unnecessary, as this would probably be in a package with
> some kind of csv-related name.
>

Is it possible to solve the problem without using type assertion?
 

>
> https://play.golang.org/p/9mSfG1m4VZ
>
>   cheers,
> rog.
>
> On 20 July 2017 at 08:05, Sofiane Cherchalli  > wrote:
>
>> Hi Silviu,
>>
>> Thanks for the reply.
>>
>> Basically I want to kinda functional map on my custom types by applying 
>> functions on base value or struct values.
>>
>> What if I want to for instance:
>>
>> - Multiply the float64 value inside CSVFloat by 2 ?
>> - or Replace a custom type value with another one from the same type?
>>
>> Thanks
>>
>>
>> On Thursday, July 20, 2017 at 5:09:40 AM UTC+2, Silviu Capota Mera wrote:
>>>
>>> Before: myfn := func(v CSVFloat) CSVFloat { return v }
>>>
>>> After: myfn := func(v Valuer) Valuer { return v }
>>>
>>> On Wednesday, 19 July 2017 16:48:07 UTC-4, Sofiane Cherchalli wrote:

 Hi!

 I'm a noob in Go and I need some guidance/help on this: 
 https://play.golang.org/p/0TGzKiYQZn

 Basically I'm implementing a CSV parser, and applying transformations 
 on column value.

 In last part of the code I'm trying to apply a function on CSVFloat 
 type which satisfies Valuer interface, but I got a compiler error.

 In Scala language, this could be done by using map function, but how to 
 do it in Golang?

 Thanks.

>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Code Review - Applying functions on custom types

2017-07-21 Thread Sofiane Cherchalli
Hi Rog,

Please inline comments.

Thx



On Thursday, July 20, 2017 at 1:58:09 PM UTC+2, rog wrote:
>
> I'm not convinced that holding all your values in a uniform way
> is going to be that helpful for you. You might be better using reflection
> to map the columns into a struct type (there's probably a package
> out there already that can do that).
>
> However, to answer without questioning the whole premise:
>
> You can't pass a function on a specific type to the more generally
> typed func(Valuer)Valuer because the value in the column might not
> be of the specific type - what should happen if the column is a string
> and you pass func(CSVFloat)CSVFloat to Apply?
>

Couldn't do checking with for instance reflection?
 

>
> Here's your code made to work, with some arguably redundant stuff
> removed. The Transformer type seemed unnecessary, as Apply
> and RemoveColumn both work with the row in place. The Type field
> in the Column struct seemed unnecessary, as the type is implied by
> the value in the column. Also, the whole notion of Type seemed
> a bit redundant as CSV files have no notion of type, and it seems like
> you want to support custom types. The CSV prefix on the type names
> seemed unnecessary, as this would probably be in a package with
> some kind of csv-related name.
>

Is it possible to solve the problem without using type assertion?
 

>
> https://play.golang.org/p/9mSfG1m4VZ
>
>   cheers,
> rog.
>
> On 20 July 2017 at 08:05, Sofiane Cherchalli  > wrote:
>
>> Hi Silviu,
>>
>> Thanks for the reply.
>>
>> Basically I want to kinda functional map on my custom types by applying 
>> functions on base value or struct values.
>>
>> What if I want to for instance:
>>
>> - Multiply the float64 value inside CSVFloat by 2 ?
>> - or Replace a custom type value with another one from the same type?
>>
>> Thanks
>>
>>
>> On Thursday, July 20, 2017 at 5:09:40 AM UTC+2, Silviu Capota Mera wrote:
>>>
>>> Before: myfn := func(v CSVFloat) CSVFloat { return v }
>>>
>>> After: myfn := func(v Valuer) Valuer { return v }
>>>
>>> On Wednesday, 19 July 2017 16:48:07 UTC-4, Sofiane Cherchalli wrote:

 Hi!

 I'm a noob in Go and I need some guidance/help on this: 
 https://play.golang.org/p/0TGzKiYQZn

 Basically I'm implementing a CSV parser, and applying transformations 
 on column value.

 In last part of the code I'm trying to apply a function on CSVFloat 
 type which satisfies Valuer interface, but I got a compiler error.

 In Scala language, this could be done by using map function, but how to 
 do it in Golang?

 Thanks.

>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: No Allman-Style, No go!

2017-07-21 Thread thorsteinssonh
I don't get it.  It's not even true K style.  
Open brace on function declarations in original K books was always on a 
new line.
It is only conditional expressions that have open braces on same line as 
the conditional.
Just check the book,

https://github.com/germanoa/compiladores/blob/master/doc/ebook/The%20C%20Programming%20Language%20-%202nd%20Edition%20-%20Ritchie%20Kernighan.pdf

Best just to call this golang style, or the wrong K style. They have 
converted their own style into syntax.

On Saturday, September 21, 2013 at 1:58:03 AM UTC, Michael Daconta wrote:
>
> Hi Go fans,
>
> I frankly was shocked to learn that a program like:
>
> package main;
>
> import "fmt";
>
> func main() 
> {
> fmt.Printf("hello, world!\n");
> }
>
> ... is currently illegal in go with the error:
>
> # command-line-arguments
> .\hello.go:6: syntax error: unexpected semicolon or newline before {
>
> From reading the newsgroups, I see that this is illegal due to the 
> automatic insertion of semi-colons; however, what if I added my own 
> semi-colons into the code as in the above.  From a language perspective the 
> above should be legal Go code.  To me, it seems like a hack for convenience 
> (making semi-colons optional) has forced a K style on everyone.
> For me, this is a show-stopper.  Frankly, I am surprised that Google would 
> enforce a coding style (K) while saying that "go fmt" frees you from 
> worrying about divergent coding styles.  Sorry, google - you cannot have it 
> both ways.  Unless the Allman-style code above is illegal in the language 
> (which makes no sense from a language semantics point of view) - get the 
> compiler to accept it. Period.
>
> Yes, I know I can write my own translator - but why?  Heck, I can just 
> stick with Java...
>
> C'mon Google, when trying to pitch a new language, you can (and should) do 
> better than this...
>
> - Mike
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Sorting user defined collection in multiple ways

2017-07-21 Thread Val
Hello Srinivas

The traditional way to achieve this in go (as showcased here 
 and here 
) is, 
to :
- declare a named type of slice
- implement 3 methods Len, Less, Swap 

- call sort.Sort 

(each attribute age, name, sal, needs its own type declaration and 3 method 
implementations).

Since Go 1.8, we can achieve basically the same with much less boilerplate 
code (as showcased here  and 
here ) 
:
- implement 1 func "less" having type  func(i, j int) bool
- call sort.Slice 

(each attribute age, name, sal, needs its own "less" func).

I suggest the latter.
HTH
Valentin

On Friday, July 21, 2017 at 3:17:29 PM UTC+2, Srinivas Kandula wrote:
>
> Hi,
> I have below requirement, could any one suggest on how i can achieve in go 
> lang using https://golang.org/pkg/sort/.
> - I have user defined data structure called Employee with attributes 
> "age", name and sal.  I want to write three different go functions that 
> sorts based on age, name and sal.
> example:-
>   sortEmployeeByAge(employeelist)
>   sortEmployeeByName(employeelist)
>   sortEmployeeBySal(employeelist)
>
> Thanks,
> Srinivas K
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Sorting user defined collection in multiple ways

2017-07-21 Thread Jan Mercl
On Fri, Jul 21, 2017 at 3:17 PM  wrote:

> - I have user defined data structure called Employee with attributes
"age", name and sal. I want to write three different go functions that
sorts based on age, name and sal.

Are you sorting a slice? https://golang.org/pkg/sort/#Slice

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Sorting user defined collection in multiple ways

2017-07-21 Thread srinik . kandula
Hi,
I have below requirement, could any one suggest on how i can achieve in go 
lang using https://golang.org/pkg/sort/.
- I have user defined data structure called Employee with attributes "age", 
name and sal.  I want to write three different go functions that sorts 
based on age, name and sal.
example:-
  sortEmployeeByAge(employeelist)
  sortEmployeeByName(employeelist)
  sortEmployeeBySal(employeelist)

Thanks,
Srinivas K

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] "interface{} says nothing", lets consider it destroys information

2017-07-21 Thread mhhcbon
here is a solution to what i described in previous.

The result of
func mustNotErr(f func() (, error)) func() () {}
is the transitivity of t -to> func (...) (..., *-*error)

mustNotErr takes in input
a func T with any inputs, and a *traling* error, 
returns in output,
the func T *less* the trailing error.

- Given
func W() (X, error){}
func W1(a A, b *B) (Y, X, error){}
- Want
func MustW() (X){}
func MustW1(a A, b *B) (Y, X){}

Which literally is,
W() (X, error) -> less a trailing error ->MustW() (X)
W1(a A, b *B) (Y, X, error) -> less a trailing error ->MustW1(a A, b *B) 
(Y, X)

Which in can be written such as
W() (X, error) -> func (...) (..., *-error*) ->MustW() (X)
W1(a A, b *B) (Y, X, error) -> func (...) (..., *-error*) ->MustW1(a A, b 
*B) (Y, X)

So the solution might looks like

mustNotErr := func(f ) t->func (...) (..., *-error*) 
{
 return func(params ...Parameters) ... {
...ret, err := f(params...)
if err != nil {
panic(err)
}
return ret...
 }
}


On Friday, July 21, 2017 at 10:32:21 AM UTC+2, mhh...@gmail.com wrote:
>
> so wise! thanks for those clarification.
>
> I did not deeply understand why it is called an identity func, and why it 
> has to be this signature.
> It seems so narrowed to a specific case, makes me unhappy.
>
> Now, i realized that even if , for some specific cases, seems to solve 
> some situations,
> it won t be enough to implement the kind of things i presented, 
> function composition (do -> to composition).
>
> My example was to simple.
>
> A better func to think about is *mustNotErr*.
>
> mustNotErr is not implementable using , but lets take a look what he d 
> be,
>
> func mustNotErr(f func() (, error)) func() () {}
>
> In plain text, it is a func that takes in parameter a func and returns a 
> func.
>
> but if you take some realistic example you ll get something like
>
> func W() (X, error){}
> func W1(a A, b *B) (Y, X, error){}
>
> And now we can observe that size, positions, and types 
> of the delayed func IO/parameters are the differences 
> that are not matched in my previous declaration of mustNotErr.
>
> mustNotErr takes no parameter, returns only 2 parameters
> f() (A,B) -> matches W, but not W1.
>
> But, intuitively we feel that W and W1 can be factorized to something like 
> this,
> a func  func(
> with any input parameters   ...
> ,   ) (
> returns any parameters,  ...
> followed,,
> by a traling error  error
> )
>
> yeah ?
>
> Using that definition, let s see what it might look likes,
>
> mustNotErr := func(f ) *???* {
>  return func(params ...Parameters) *???* {
> ...ret, err := f(params...)
> if err != nil {
> panic(err)
> }
> return ret...
>  }
> }
>
> Where Parameters{Value,Type}
> Where "...,error" ~~ any front parameters until error
> Where "...ret, err :=" ~~ any front parameters until error
> Where "return ret..." ~~ any values in []Parameters
>
> The problem now is about the type of the returned func,
> it is not  anymore, because the error return parameter was removed,
> on the other hand, as a declarer we dont know enough about f, to return a 
> complete function,
> it literally is func(...)(...)
>
> But func(...)(...) is not a type a receiver can consume
>
> At that point, some sort of templating is required, indeed,
> or what, partial types ? looks bad...
>
>
> On Thursday, July 20, 2017 at 10:25:30 PM UTC+2, Jesper Louis Andersen 
> wrote:
>>
>> On Mon, Jul 17, 2017 at 11:07 AM  wrote:
>>
>>> does it make sense to consider a "value type of any type that carries 
>>> out its input type" ?
>>>
>>
>> Yes. This is called a "universal" and is related to the concept of 
>> parametrization by J. Reynolds.
>>
>> Your 'do' function is often called 'id' for the obvious reason that it is 
>> the identity function. In SKI logic it is the I combinator. If we annotate 
>> the type as you would in type theory, you would write something like
>>
>> id : (T : Type) -> T -> T
>> id t x = x
>>
>> to say that the function can be instantiated with any type 'T' you 
>> desire. The actual implementation of 'id' takes two parameters. First it 
>> takes the desired type and then it takes the parameter and returns it. 
>> Writing 'id Int' is a partial invocation. It "plugs in" the T and yields a 
>> function of type 'Int -> Int'. Likewise, 'id String' plugs in strings in 
>> the position. Interestingly, Reynolds showed that if the function 'id' is 
>> to work for *any* type T at the same time, it *must* have the above 
>> implementation. No other implementation is valid. This is the concept of 
>> parametrization. Even better, the type T can be a type outside of the type 
>> system of the programming language!
>>
>> But do note there is no 

[go-nuts] Re: How do you test a server?

2017-07-21 Thread Simon Ritchie
My scaffolding tool generates a web server and some unit and integration 
tests.  The tests use Peter Gotz' mocking framework pegomock.  If you 
generate a server with the scaffolder, you can look at the source code and 
see how it works.

https://github.com/goblimey/scaffolder

By the way, not everybody in the Go community believes in the use of 
mocking frameworks.  Donovan and Kernighan's The Go Programming Language 
advocates a different approach.  This is used to test the entire Go 
infrastructure, so it's clearly effective.  However, I come from the London 
Java community and we use mocking frameworks a lot over here.

I used pegomock because I couldn't get gomock to work.  I managed to get 
pegomock working and I found that Peter was much more responsive when I 
reported a couple of issues with it.

For system testing, you can use the Firefox Selenium addon, which works at 
the HTTP level and doesn't care what language you used to create the 
server.  It  records a web session and produces tests in various formats, 
which you can then edit.  For example, if you record a test that creates an 
object in a database and it produced one with ID 42, and then you record a 
test that displays object 42, you can edit the test to replace the ID with 
a wildcard.

Before I wrote my scaffolder, I experimented by hand-crafting a very simple 
web server: https://github.com/goblimey/films.
I recorded some Selenium tests for this.  They are in  
tests/system/selenium.

Obviously, there is a general point here.  There are lots of tools out 
there that run penetration, performance and other types of testing on http 
servers and none of them care what technology you used to create the server.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.